Wednesday, 15 July 2015

c# - Create Master/Detail with Combobox and DataGridView -


I have a combo box, in which an escalator is the elements loaded from the table (group). I have a datagrid view, which is linked to another table (users).

When I load the form, the combo is filled with the group, and the datagrid is filled with Visible Users (all users)

1) I want to be able to select a group from the combo box (dropdownlists), and then to refresh the datagrid view with users of that selected group ...

2) and how do I get an insertion link in DataGridView Can I eat Suppose I want to show the name of the group in the last column of each user ...

PS:

I have an xsd dataset In my VS2008 project, its corresponding Table Adapters (GroupTable Adapter, UserTable Adapter) and some SQL-methods were added to each adapter.

1) Set a binding source for both tables.

  Binding source bsGroup = new binding source (); Binding source bsUser = new binding resource (); BsGroup.DataSource = MyDataSet.Tables ["Groups"]; BsUser.DataSource = MyDataSet.Tables ["User"];  

2) Set up your combo and grid data source.

  MyCombo.DataSource = bsGroup; MyCombo.DisplayMember = "GroupName"; // whatever your column is MyCombo.ValueMember = "GroupID"; MyGrid.DataSource = bsUser;  

3) Set up a chosen index change event for the combo and use it to change the filter on the BSUSIR binding pool.

  MyCombo Selected index - + new system .EventHandler (MyCombo_SelectedIndexChanged); Private Zero MyCombo_SelectedIndexChanged (Object Sender, System.EventArgs E) {// This will depend on your column names, clearly string filter = string.Format ("GroupID = {0}", MyCombo.SelectedValue); BsUser.Filter = Filter; }  

This work has been taken from OK ....

(Yes, I also posted it on MSDN because I was in haste)


No comments:

Post a Comment