Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Master detail
 

Master detail

how can i make DataGridView to enable master Detail

and supported it

Dany85  Thursday, February 23, 2006 11:22 AM
Add you master and detail tables to a dataset, create a relation between them, then bind the grid to the dataset.
CommonGenius.com  Thursday, February 23, 2006 6:37 PM
can you write code snippet about it please
Dany85  Friday, February 24, 2006 4:45 PM

You can use SqlDataAdapter and Dataset to create Master-Detail tables.

Generate data adapters for both Master and Detail.

Fill the data using Dataset and then generate a Relation between both tables.

' Connect to Database and fill Data Adapter with DataSets.

Dim Conn as new SqlConnection(�lt;PROVIDER=�.>�

Dim DAMast as New SqlDataAdapter(“Select * from Master�,Conn)

Dim DADetail as New SqlDataAdapter(“Select * from Detail�Conn)

Dim DS as New DataSet

DAMast.Fill(DS,”Master�

DADetail.Fill(DS,”Detail�

' Create relation for the DataSet.

Dim myDataRelation As DataRelation myDataRelation = New DataRelation _

("MastDtls", DS.Tables("Master").Columns("Code"), _

DS.Tables("Detail").Columns("Mast_Code"))

' Add the relation to the DataSet.

DS.Relations.Add(myDataRelation)

' Assign Database to grids.

GridMast.SetDataBinding(DS,"Master")

GridDetail.SetDataBinding(DS, "Master.MastDtls")

MudMike  Thursday, March 16, 2006 1:53 PM
How about composite keys for primary keys? How do you add them in the relationship? Ben
BenGoodman  Friday, August 07, 2009 2:25 PM

You can use google to search for other answers

Custom Search

More Threads

• Binding to a data subset
• why would dgvcolumns be generated as friend withevents.
• Change string column to checkbox column
• DataGridView and ContextMenu's
• Gridview
• Performance issues when iterating throug DataGridView.SelectedCells
• Getting current row values from my BindingSource in C# VS 2005!!!
• Databinding to control
• Datagrid databinding with a custom SQL statement
• DataGrid Import/Export