问题描述
我在 Windows 窗体上有 2 个 DropDownList 组合框,它们都从同一个数据集(员工列表)填充,但它们用于不同的目的(项目经理/审阅者).
I have 2 DropDownList ComboBoxes on a Windows Form, both populated from the same DataSet (a staff list), but they serve different purposes (project manager/reviewer).
如果我将它们的 DataSource 都设置为 DataSet,它们都绑定到 DataSet 并同时更改.
If I set the DataSource for both of them to the DataSet, they are both bound to the DataSet and change in tandem.
我是否遗漏了什么,或者我是否必须以编程方式将数据集的行和列读入 Items 集合,而不是直接使用 DataSet?
还是复制 DataSet?
Am I missing something, or will I have to read the rows and columns of the data set into the Items collection programmatically instead of using the DataSet directly?
Or replicate the DataSet?
在另一个表单上,我多次遇到同样的问题.
On another form, I have the same problem several times.
推荐答案
在 bytes.com
combo1.DataSource = payDS.Tables[0];
combo1.BindingContext = new BindingContext();
combo1.DisplayMember = "staff_name";
combo1.ValueMember = "staff_id";
combo2.DataSource = payDS.Tables[0];
combo2.BindingContext = new BindingContext();
combo2.DisplayMember = "staff_name";
combo2.ValueMember = "staff_id";
对我有用.
这篇关于来自同一数据集的多个 ComboBox 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!