Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1610
  • Last Modified:

DataGridView with Parent/Child relationship?

Is it possible to have a single DataGridView that contains a row with a master record and then contains multiple child records that can be expanded underneath the parent row? If a parent contains no child records, it displays normally, however, if a parent has child records, then place the "+" sign in the DGV RowHeader or somewhere at the beginning of the row to signify child records exist?

Thanks!
0
BlakeMcKenna
Asked:
BlakeMcKenna
2 Solutions
 
Fernando SotoCommented:
Hi  BlakeMcKenna;

The DataGridView control found in the Toolbox does not support that type of Master/Detail display option. To do what you would like you will need to use the older control called DataGrid control. You will need to add this control to the Toolbox before it can be used. Microsoft has replaced it with the newer control the DataGridView bit it does not do everything the older control did. To add the DataGrid to the Toolbox you can do the following.

1. In the Toolbox right click on the Tab you wish to place the control in such as the Data tab.
2. Click on the item "Choose Items..."
3. In the new window in the .Net Framework Components find the control DataGrid. Be careful there is also a DataGrid for Web apps. Select the one for Forms.
4. Click on the OK button.

The control is now in the Tab you placed it in and can be dragged onto the design surface.

The Following link will show you how to set it up
Creating Master-Details Lists with the Windows Forms DataGrid Control
0
 
CodeCruiserCommented:
Here is an alternative using a TreeView

http://www.codeproject.com/Articles/23746/TreeView-with-Columns
0
 
BlakeMcKennaAuthor Commented:
CodeCruiser,

Thank you for the link.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now