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 控件
基础教程推荐
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 如果条件可以为空 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
