One DataSource for multiple controls

后端 未结 4 685
孤独总比滥情好
孤独总比滥情好 2021-01-18 13:47

I have two ListBox in my winforms application, I assigne a datasource for both of them as follow:

private void MakeMeasurementUnits()
{
    var          


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-18 14:25

    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.

提交回复
热议问题