|
...and this has what to do with C#?
|
|
|
|
|
Either I have been smoking something really GOOOOOOD!!!, or this makes no sense whatsoever.. Could you clarify your question, please?
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
I am using the following code to populate xtraGrid from PostgeSQL but as you see I am using the data_table.Columns[0].ToString() and data_table.Columns[1].ToString() to refer to the columns because it's not accepting the "field_name"
what can I do to make refer to the field name by name only instead of the data_table.........!
sql_connection = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["JassimSQL"].ConnectionString);
sql_connection.Open();
sql_command = new NpgsqlCommand("populate_personal_info_title2", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
sql_adapter = new NpgsqlDataAdapter();
sql_adapter.SelectCommand = sql_command;
data_set = new DataSet();
DataTable data_table = new DataTable(); ;
sql_adapter.Fill(data_table);
cboTitle.Properties.ValueMember = data_table.Columns[0].ToString();
cboTitle.Properties.DisplayMember = data_table.Columns[1].ToString();
cboTitle.Properties.DataSource = data_table;
cboTitle.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo(data_table.Columns[1].ToString(), 50, "education_name"));
cboTitle.Properties.ShowHeader = false;
cboTitle.Properties.NullText = "UNSPECIFIED";
cboTitle.Properties.PopupSizeable = false;
cboTitle.Properties.PopupHeaderStyle.HAlignment = DevExpress.Utils.HorzAlignment.Default;
cboTitle.Properties.ShowFooter = false;
cboTitle.Properties.PopupWidth = 50;
|
|
|
|
|
How about:
cboTitle.Properties.ValueMember = data_table.Columns[0].ColumnName
|
|
|
|
|
no.
what i mean is like this:
cboTitle.Properties.ValueMember = "field_name"
|
|
|
|
|
That usually works just fine unless the field name is auto assigned or typed incorrectly. Try MessageBox.Show(dataTable.Columns[0].ColumnName) and see what you get as a result. Is it what you are expecting?
|
|
|
|
|
AFAIK you can identify grid columns by name once you have assigned their name to their Name (or ColumnName?) property.
|
|
|
|
|
Not sure about what your question is (I guess I still have to improve my English) but if it helps, ToString() method on a DataColumn object returns the same as its Expression property, it does not return its name.
|
|
|
|
|
Dear All --
I have a form in c#, consisting of say 1 combobox and 4 textboxes. Combobox will have values from 1 to 4 and the name of the textboxes be txt1, txt2,.. txt4. Depending on the value chosen in combobox, the txtboxes should hide or show.
Is something like the below code possible.
for (int i = 0; i < n; i++)
{
(TextBox)("txt" + i).Hide;
}
or is there some other better way of doing the same.
Sorry, if the subject name is not in lines with the body/matter.
cheers
|
|
|
|
|
the 4 textboxex are static or dynamic ? i mean you will have always those 4 textboxs or maybe change on 3 or 5 ?
|
|
|
|
|
On the Combox1 Selectedindexchanged Event (when you select a Value)
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (Control tb in this.Controls)
{
if (tb.Name == comboBox1.Text )
tb.Visible = false;
}
}
|
|
|
|
|
Try:
foreach (Control c in Controls)
{
TextBox t = c as TextBox;
if (t != null)
{
t.Hide();
}
}
If you want to select the text box(es) to hide in the ComboBox, then assign a numeric value to each TextBox.Tag property. You can then compare this to the numeric value in your combo box before deciding if you should hide or not.
Don't forget to reveal ones you have hidden already...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
This seems a fact unfamiliar to a lot of people, however even in WinForms you can easily get at a control by its name, like this:
Control c=this.Controls[name];
|
|
|
|
|
I'd forgotten that...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Ain't that so.
|
|
|
|
|
|
Don't bother - he is posting this in every forum he can find.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Dear All --
Go through the code below. Pour in your valuable suggestions.
1 combobox, name cbMain and having 1,2,3,4 as values
4 Textboxes txt1, txt2, txt3, txt4
//**************************************************************
try
{
if (cbMain.SelectedItem.ToString() == "1")
{
txt2.Hide();
txt3.Hide();
txt4.Hide();
}
else if (cbMain.SelectedItem.ToString() == "2")
{
txt2.Show();
txt3.Hide();
txt4.Hide();
}
else if (cbMain.SelectedItem.ToString() == "3")
{
txt2.Show();
txt3.Show();
txt4.Hide();
}
else if (cbMain.SelectedItem.ToString() == "4")
{
txt2.Show();
txt3.Show();
txt4.Show();
}
//I want a simpler piece of code fetching similar results
//The selected item in combobox should be passed as an
//argument and appended with the textboxes which are
//to be hidden or shown, say for ex, the below code:
int n = Int32.Parse(cbMain.SelectedItem.ToString());
for (int i = 1; i <= n; i++)
{
//("txt" + i).Show();
//What line will make the trick
}
for (int i = n+1; i <= cbMain.Items.Count; i++)
{
//("txt" + i).Hide();
//What line will make the trick
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
cheers
|
|
|
|
|
Luc won't read that!
Edit it, and use the "Code block" widget to put <pre>...</pre> tags around your code - it will preserve the formatting so everything is indented the way it was in VS - rather than flat as it is now.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
OriginalGriff wrote: Luc won't read that!
Right. There are minimum quality levels I don't want to cross. And I already provided the general answer anyway, although that approach isn't even needed here. Something like
txt1.Visible=cbMain.Text=="1";
txt2.Visible=cbMain.Text=="2";
...
would probably suffice. No ifs, no fors.
|
|
|
|
|
Luc --
Say you have 100 textboxes or controls to be hidden acc. to choice, then will you write 100 statements or probably even more ?
cheers
|
|
|
|
|
thomforum wrote: then will you...
No.
I never write 10 or more similar statements. They invented loops for such situations.
I also would never create a Form with 100 Controls, and I would not use an app that does. It is pure madness.
I did answer your original question. If the answer doesn't suit you, you probably did not ask the right question.
|
|
|
|
|
Luc --
My apologies, on not seeing your first post. Well, that covers my requirement.
cheers
|
|
|
|
|
Hi,
I have been facing an issue while using CDOEXM.dll from my .NET Framework 2.0 code (written in C#). We are trying to create a mailbox on an Exchange Server (which is 2003). We have checked for correctness of the code in terms of NULL value etc. The code which gives the error is below:
CDOEXM.IMailboxStore mailbox;
mailbox = (IMailboxStore)User.NativeObject;
mailbox.CreateMailbox(maildb);
The error message that we get is:
Unable to cast COM object of type 'System.__ComObject' to interface type 'CDOEXM.IMailboxStore'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{25150F41-5734-11D2-A593-00C04F990D8A}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))
I would like to emphasize that the very same code has been running on .NET Framework 1.1 without any issues. I understand that there is a typecasting issue, but I am unable to understand that how to resolve this.
Any help will be much appreciated for this long drawn issue. Please let me know if you would like to get any more information from me.
Cheers,
Som
|
|
|
|
|
I found this sentence in this[^] article: "This cast does not succeed at run time if CDOEXM is not installed on a computer". Have you checked that?
|
|
|
|