Question

This is using winforms.

I have a listbox and a combo box, both tied to the same datasource, same display members, same value members. All is bound just fine and the items show up in both the controls.

The problem is when I change a selection in one control, it moves to the same index in the other control. I don't have any events tied to either control. It is just happening on its own. Has anyone ever run into this?

Was it helpful?

Solution

The datasource is a separate object. When one of the controls changes the datasource active row it sends out an update notification to the other controls to move accordingly. This is normal and expected behavior.

The idea behind it is to simplify navigating record sets while keeping all the bound controls in sync.

If you don't want that, use two datasources tied to the same underlying data.

OTHER TIPS

This is because both the controls share the same BindingContext/CurrencyManager. Controls inherit the BindingContext from their container control. A BindingContext maintains only one CurrencyManager per DataSource. If you want to have two different CurrencyManagers, you need to have two BindingContexts.

So when once of the controls selection is changed, currencyManagaer.Current gets updated. This affects all the controls that share the same DataSource.

Instantiate a new BindingContext and assign it to the BindingContext property of one of the ComboBoxes:

comboBox2.BindingContext = new BindingContext();

This should solve the problem.

I think that might be intended to be a feature. For Master/Detail type forms.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top