One DataSource for multiple controls

牧云@^-^@ 提交于 2019-12-01 18:09:45

The listbox seems to cache the binding source. This is default behavior. If you want to avoid this, the easy way is to create a copy of the list to bind to the second data source:

lbxXunit.DataSource = units;
lbxYunit.DataSource = units.ToList();

This is useful when you have multiple views of the same data and want to synchronize the selection of these items.

Yes, this is normal behaviour. It happens because the ListView control uses a BindingSource object to track the currently selected item. (A List has no way to track a selected item without a BindingSource.)

By default, a DataSource in a WinForms control uses a BindingSource created for it by the WinForms system itself.

You can read more about the BindingSource at: http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx

There is an article here which might help too: http://blogs.msdn.com/b/bethmassi/archive/2007/09/19/binding-multiple-comboboxes-to-the-same-datasource.aspx

The behavior you have noted is the default/correct behavior for winforms controls. You can achieve what you are after by setting a new BindingContext for your second listbox control without creating a copy of your data source.

BindingContext

This is correct behaviour. The datasource management in WindowsForms keeps track of the selected item on control and manipulates binded data too.

The resolution you've found already: is assign 2 different data sources objects to these controls.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!