I'm using winforms and I've got a comboBox that represents an IQueryable. Below the combobox is a series of textboxes that I would like to be bound to the currently selected from the combo box.
Here is my code.
public partial class TestForm : Form
{
public DataClassesDataContext DataContext;
public IQueryable<T> datasource;
// Ctor
public TestForm()
{
InitializeComponent();
// L2S data context
this.DataContext = new DataClassesDataContext();
// Get the variable for the data source
this.datasource = this.DataContext.Ts;
// setup the binding for the combobox
this.comboBox1.DataSource = this.datasource;
this.comboBox1.DisplayMember = "Description";
this.comboBox1.ValueMember = "Id";
// assign the databindings of the text boxes to the selectedItem of the combo box
// this is where the problem is, afaik
TId.DataBindings.Add(new Binding("Text", this.comboBox1.SelectedItem, "Id"));
TUser.DataBindings.Add(new Binding("Text", this.comboBox1.SelectedItem, "User"));
TDescription.DataBindings.Add(new Binding("Text", this.comboBox1.SelectedItem, "Description"));
}
Doing this binds everything, When I change the values in the text boxes, it updates the initially selected item in the combo box just fine. Even when I change the description, it updates the displayed text in the drop don, all that is great.
However, when I select a different item from the drop down, the text boxes don't bind to that newly selected item, they stay bound to the old one.
Do I need to remove and re-add my bindings every time the selection changes on the combo box?