使用ComboBox的C#Master Detail和使用tableAdapters的DataGridView [英] C# Master Detail using ComboBox and DataGridView with tableAdapters

查看:96
本文介绍了使用ComboBox的C#Master Detail和使用tableAdapters的DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Combobox。它的元素是从sqlserver表加载的。该表称为组。我使用Text属性的名称和Tag的id字段(我使用Visual Studio选项将Combobox链接到表格)

我还有一个DataGridView,链接到另一个表(用户)。当我加载表单时,组合充满了组,datagridview充满了用户。 dataGridView充满了所有用户

1)我希望能够从ComboBox(dropDownList)中选择一个组,然后使用属于该选定组的用户刷新DataGridView。 ..


2)最后,我如何在DataGridView中构建和显示连接关系?假设我想在最后一列显示groupName,除了每个用户名......

PS:我在我的VS2008项目中创建了一个XSD数据集,并生成了相应的tableAdapters(groupTableAdapter) ,userTableAdapter)和一些sql方法添加到每个适配器,所以我应该继续使用这些对象来解决我的2个问题...


提前多多感谢,

< hr class ="sig"> Itexa
http://www.itexa.com.ar
自定义Web应用程序

解决方案

1)为两个表设置BindingSource。



 BindingSource bsGroup =  new  BindingSource(); 



 BindingSource bsUser =  new  BindingSource(); 



 



 bsGroup.DataSource = MyDataSet.Tables [" Group" ]; 



 bsUser.DataSource = MyDataSet.Tables [" User" < /跨度>]; 


I have a Combobox. Its elements are loaded from a sqlserver table. The table is called group. I use name for Text property, and id field for Tag (I link the Combobox to the table using Visual Studio options)

I also have a DataGridView, linked to another table (user). When I load the form, the combo is filled with groups, and the datagridview is filled with users. The dataGridView is filled with 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 finally, How could I build and show a join relationship in the DataGridView? Let's say I want to show the groupName in the last column, besides each username...

PS:
I have a XSD Dataset created in my VS2008 project with its corresponding tableAdapters generated (groupTableAdapter, userTableAdapter) and some sql-methods added to each adapter, so I should keep using these objects for solving my 2 questions...

Thanks a lot in advance,


Itexa http://www.itexa.com.ar Custom Web Applications

解决方案

1) Set up a BindingSource for both tables.

BindingSource bsGroup = new BindingSource();

BindingSource bsUser  = new BindingSource();

 

bsGroup.DataSource = MyDataSet.Tables["Group"];

bsUser.DataSource = MyDataSet.Tables["User"];


这篇关于使用ComboBox的C#Master Detail和使用tableAdapters的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆