I’m having problems with BindingContext in a .NET application. I need to populate 6 comboboxes with the same datasource but the first 3 comboboxes must be indepedent from the last 3 comboboxes.
I coded the following:
combo_Bancos_cheque.DataSource = bancos;
combo_Bancos_cheque.DisplayMember = "Nombre";
combo_Bancos_cheque.ValueMember = "IDBanco";
combo_ctas_cheque.DataSource = bancos;
combo_ctas_cheque.DisplayMember = "NoCuenta";
combo_clabe_cheque.DataSource = bancos;
combo_clabe_cheque.DisplayMember = "CLABE";
combo_Bancos_dep.BindingContext = new BindingContext();
combo_Bancos_dep.DataSource = bancos;
combo_Bancos_dep.DisplayMember = "Nombre";
combo_Bancos_dep.ValueMember = "IDBanco";
combo_ctas_dep.DataSource = bancos;
combo_ctas_dep.DisplayMember = "NoCuenta";
combo_clabe_dep.DataSource = bancos;
combo_clabe_dep.DisplayMember = "CLABE";
The first 3 comboboxes work fine, when combo_Bancos_cheque changes combo_ctas_cheque and combo_clabe_cheque also change which is the expected behaviour. Then I create a new BindingContext to unbind 4,5 & 6 combobox which also use the same datasource.
The problem here is: when combo_Bancos_cheque value changes, combo_ctas_dep & combo_clabe_dep also change but I don’t want this, I need these comboboxes to change only when combo_Bancos_dep changes.
I’m new to BindingContexts, what am I missing?
This is a quick guess, but don’t you need to point combo boxes 5 and 6 to the same binding context as combo 4 (combo_Bancos_dep) ?
What if you create the new binding context into a variable, and then set it to CBs 4,5, and 6 ?
EDIT:
I just checked to confirm, and the above is correct. You were really close, you just needed to set your new BindingContext to combo_ctas_dep and combo_clabe_dep.
Here is what you posted with the change: