AWestEng
asked on
Databinding Combobox
Hi
I have a combobox that I use databinding on.
Me.cboEmploymentCondition. DataBindin gs.Add(New System.Windows.Forms.Bindi ng("Text", m_tbl_BindingSourceEmploye d, "EmploymentCondition", True))
The problem is not if there are any data in the DB that matches the values in the combobox it's when it dosen't. If the data dosen't match any of the texts that's in the combobox it keeps the parent value.
So if I "send" "Test1" to the cbo it shows "Test1" if this text is in the combobox.
If I then "send" "Test2" and that text dosen't exist in the cbo it will still show the text "Test1".
If the text is missing I what the box to show a empty row (no text).
Is this possible to fix this?
I found this, but I can't get it to work
http://windowsclient.net/blogs/faqs/archive/2006/07/12/how-can-i-add-a-null-or-dbnull-entry-to-my-bound-combobox.aspx
I have a combobox that I use databinding on.
Me.cboEmploymentCondition.
The problem is not if there are any data in the DB that matches the values in the combobox it's when it dosen't. If the data dosen't match any of the texts that's in the combobox it keeps the parent value.
So if I "send" "Test1" to the cbo it shows "Test1" if this text is in the combobox.
If I then "send" "Test2" and that text dosen't exist in the cbo it will still show the text "Test1".
If the text is missing I what the box to show a empty row (no text).
Is this possible to fix this?
I found this, but I can't get it to work
http://windowsclient.net/blogs/faqs/archive/2006/07/12/how-can-i-add-a-null-or-dbnull-entry-to-my-bound-combobox.aspx
/* Create a new Customer */
Customer cust = new Customer("Joe", null);
/* Add null value */
DataRow row = statesTable.NewRow();
/* Enter a null row (ComboBox will show blank) */
row["Name"] = "";
row["Code"] = DBNull.Value;
/* Add the row to DataTable */
statesTable.Rows.Add(row);
/* Bind the States ComboBox to the states DataTable */
this.statesCB.DisplayMember = "Name";
this.statesCB.ValueMember = "Code";
this.statesCB.DataSource = statesTable;
/* Bind the ComboBox SelectedValue to the customer */
/* business object */
this.statesCB.DataBindings.Add("SelectedValue", cust, "StateID", true);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.