使用 Combobox 和 DataGridView 创建主/详细信息
我有一个 ComboBox,其元素从 sqlserver 表(组)加载。 我还有一个 DataGridView,链接到另一个表(用户)。
当我加载表单时,组合填充了组,并且 datagridview 填充了用户(所有用户)
1) 我希望能够从 ComboBox (dropDownList) 中选择一个组,然后用属于该选定组的用户刷新 DataGridView...
2) 以及如何在 DataGridView 中显示联接关系?假设我想在每个用户的最后一列中显示组名...
PS:
我在 VS2008 项目中创建了一个 xsd 数据集,其 生成对应的tableAdapter (组表适配器、用户表适配器) 并添加了一些 sql 方法 适配器
I have a ComboBox with its elements loaded from a sqlserver table (groups).
I also have a DataGridView, linked to another table (users).
When I load the form, the combo is filled with groups, and the datagridview is filled with users (all the users)
1) I want to be able to select a group from the ComboBox (dropDownList), and then to refresh the DataGridView with the users that belong to that selected group...
2) And How can I show a join relation in the DataGridView? Let's say I want to show the groupName in the last column of the each user...
PS:
I have an xsd Dataset created in my VS2008 project with its
corresponding tableAdapters generated
(groupTableAdapter, userTableAdapter)
and some sql-methods added to each
adapter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1) 为两个表设置 BindingSource。
2) 设置组合和网格数据源。
3) 为 Combo 设置 SelectedIndexChanged 事件,并使用它来更改 bsUser 绑定源上的过滤器。
这工作正常...取自 此处。
(是的,我也在 MSDN 上发布了这个,因为我很着急)
1) Set up a BindingSource for both tables.
2) Set up your Combo and Grid DataSources.
3) Set up a SelectedIndexChanged event for the Combo and use it to change the filter on the bsUser bindingsource.
This worked fine... taken from here.
(Yes, I posted this also on MSDN because I was in a hurry)