F
Frank Lamers
Hi,
I have a problem with a Combobox after binding to a datatable. I displayed a column of a table with code similiar to what Tom Krueger mentioned here:
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter da = new
System.Data.SqlClient.SqlDataAdapter(
"Select * from Customers", conn);
da.Fill(ds);
System.Data.DataTable dt = ds.Tables[0];
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = "CustomerID";
This works fine, the column 'CustomerID' is displayed. Now the problem:
1. I can just assign values which are already listed in the column.
Example:
comboBox1.Text = "4711"
assigns the text '4711' only if it is listed in the column 'CustomerID' (and by this in the list of the combobox). Otherwise the text is unchanged.
2. I cannot check the Combobox whether it contains the string
Example:
if not comboBox1.Items.Contains("4711") then...
will always result in the string being NOT in the combobox regardless whether it is part in the datatable colum (and by this in the combobox) or not.
Any ideas how to solve this problem?
Regards
Frank Lamers
I have a problem with a Combobox after binding to a datatable. I displayed a column of a table with code similiar to what Tom Krueger mentioned here:
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter da = new
System.Data.SqlClient.SqlDataAdapter(
"Select * from Customers", conn);
da.Fill(ds);
System.Data.DataTable dt = ds.Tables[0];
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = "CustomerID";
This works fine, the column 'CustomerID' is displayed. Now the problem:
1. I can just assign values which are already listed in the column.
Example:
comboBox1.Text = "4711"
assigns the text '4711' only if it is listed in the column 'CustomerID' (and by this in the list of the combobox). Otherwise the text is unchanged.
2. I cannot check the Combobox whether it contains the string
Example:
if not comboBox1.Items.Contains("4711") then...
will always result in the string being NOT in the combobox regardless whether it is part in the datatable colum (and by this in the combobox) or not.
Any ideas how to solve this problem?
Regards
Frank Lamers