Multiple ComboBox controls from the same Dataset(来自同一数据集的多个 ComboBox 控件)
问题描述
我在 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 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:来自同一数据集的多个 ComboBox 控件
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
