我有两个数据包到同一个BindingList的ListBox.
问题是当从GUI更改所选项时,它正在改变BindingList中的位置,然后BindingList发信号通知另一个ListBox以更改其所选项.
所以我已经同步了两个ListBoxes Selected Item,这对我不利.
我想保持项目列表同步.没有光标位置.
如何禁用该光标以使其不被维护?
示例代码(只需在设计时向表单添加两个ListBox,并注册SelectedIndexChanged事件并使用按钮注册按钮单击事件):
public partial class Form1 : Form { BindingListlist = new BindingList (); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { list.Add("bla1"); list.Add("bla2"); list.Add("bla3"); this.listBox1.DataSource = list; this.listBox2.DataSource = list; } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedIndex != -1) System.Diagnostics.Trace.WriteLine("ListBox1: " + listBox1.SelectedItem.ToString()); } private void listBox2_SelectedIndexChanged(object sender, EventArgs e) { if (listBox2.SelectedIndex != -1) System.Diagnostics.Trace.WriteLine("ListBox2: " + listBox2.SelectedItem.ToString()); } // Register this event to a button private void button1_Click(object sender, EventArgs e) { list.Add("Test"); } }
谢谢, - 兰.
将此行添加到Form_Load
:
this.listBox1.BindingContext = new BindingContext();