内容摘要 -
全文 -
如何在用一个数据源DataTable绑定两个控件,确保变化不反映在两个控件中?( How to bind two controls to the same DataTable without having changes in one control also change the other control?)
我们在一个Form中放置一个ListBox和一个ComboBox控件,当数据源是一个DataTable而且绑定的ValueMember一致的时候我们选择ListBox中的一个Item时,ComboBox控件中的相同的Item也会被自动选中,我们可以采取建立新的上下文绑定对象来拒绝这样的同步操作 comboBox1.DataSource = dataset.Tables[ "Items" ]; comboBox1.ValueMember = "CustomerID"; comboBox1.DisplayMember = "CustomerID";
listBox1.BindingContext = new BindingContext(); // 设置新的上下文绑定对象 listBox1.DataSource = dataset.Tables[ "Items" ]; listBox1.ValueMember = "CustomerID"; listBox1.DisplayMember = "CustomerID";
|