Search code examples
c#data-bindingcombobox

Combobox binding does not update


I'm trying to bind a combobox to a value in data set I navigate through using a binding navigator.

I have a form, and some textboxes bound to a dataset through a binding navigator.

the binding to a textbox is simple:

this.catActualTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.myBindingSource, "CatActual", true))

It works perfectly, but I need to change one of these textboxes with a combobox. The textboxes show numbers (keys) and I want to show the related descriptions (values). So I use a combobox. I load the combobox with a DataTable, which has two columns "IdCatActual" (the keys) and "Descrip" (the values). It shows correctly in the form, but it does not update when navigate:

this.catActualComboBox1.DataSource = myDataTable;
this.catActualComboBox1.DisplayMember = "Descrip";
this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.myBindingSource, "CatActual"));

Solution

  • Finally I got the answer.

    I was using the wrong porperty. I must bind "SelectedValue" property instead "SelectedItem" property.