0
A
回答
1
最简单(也是最好)的方法是将ListBoxes'
(甚至3,4或更多)DataSource
绑定到同一个。我们必须使用BindingList<>
而不是List
来有利于通知集合中的更改。
BindingList<object> listData = new BindingList<object>();
listBox1.DataSource = listData;
public void ShowForm2(){
ListBox list = new ListBox();
list.DataSource = listData;
Form f = new Form() { BindingContext = this.BindingContext };//Set BindingContext the same to synchronize tracking item in both listBoxes.
list.Parent = f;
f.Show();
}
//This is used to add new item to the source
public void AddItem(object item){
listData.Add(item);
}
//This is used to remove an item from the source
public void RemoveItem(object item){
listData.Remove(item);
}
//This is used to remove an item by index from the source
public void RemoveItemAt(int index){
listData.RemoveAt(index);
}
尝试将控件添加到自己的窗体中。致电ShowForm2()
以显示表格2。然后尝试拨打AddItem
添加一些项目进行测试。通常我们添加一个字符串作为列表框的新项目(AddItem("item string")
)。
+0
完美!谢谢。 – progfa
相关问题
- 1. iPhone && Chipmunk-如何同步两种形状
- 2. 同步两个列表框
- 3. 从第二种形式添加项目到列表框
- 4. 不能以不同的形式添加项目到列表框
- 5. 如何同步进度条与列表框项目删除c#
- 6. 同步两个项目(同步使用的框架)
- 7. 列表框项目样式 - 如何显示两行中的项目..?
- 8. 列表框中的项目的不同项目样式
- 9. 如何两种形式
- 10. 同步两个android项目
- 11. 如何获得项目的频率列表中的两种不同长度
- 12. 如何同步两个列表框的滚动?
- 13. 如何同步两个列表框的滚动?
- 14. 如何从列表框中获取项目并以另一种形式在列表视图中显示它们?
- 15. 两种形式的复选框
- 16. 同步项目列表,跨服务器
- 17. 具有相同FormGroup的两种形式?
- 18. 使用上两种不同的形式
- 19. 两种不同形式的图像盒
- 20. 如何让两个git subdirs在不同的项目中同步?
- 21. 如何同步两种方法
- 22. 如何同步两种方法?
- 23. 如何同时具有另一种形式的第一种形式上单击项目开放
- 24. 以一种形式提交两个不同的目的地
- 25. WP7列表框项目不同步滚动时
- 26. 如何将第二种形式的列表框上的选定项目返回到Visual Basic中的主窗体?
- 27. Knockout.js - 如何使用'foreach'显示项目列表2种不同的方式?
- 28. 两个项目版本的同步
- 29. 添加的选项复选框列表阵列Symfony的2种形式
- 30. 双列表框 - 如何在两个列表框之间移动项目?
将它们设置为相同的数据绑定源 – Sayse