none
How to use Parent-Child relationTable in the datagridview

    Question

  • Hi
    i have to show the parent - child relationship table in the datagridview
    i have two tables, Items and subItems links with ID.
    Like in the datagrid the "+" sign will come in the parent row and then we can show the details of the child tables .
    i can show in the datagrid , but i have to  do it in the datagridview.
    While click on the parent row / "+" sign , the child details will be appear.
    can it possible in DATAGRIDVIEW.

    thanxs

    Wednesday, January 30, 2008 1:41 PM

Answers

  •  

    Hi jeeban,

    The DataGridView does not have build-in support for displaying master/detail data in one DataGridView. You still can use this DataGrid control if it meets your needs; the DataGrid is still supported in .Net FrameWork 2.0.

    It is recommended you use two DataGridViews to show the master/detail data; one for the master table and the other for the details table. Here is a sample for your reference.

    ·         How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls
    http://msdn2.microsoft.com/en-us/library/c12c1kx4.aspx

    If you still want to show this kind of data in one DataGridView like the DataGird does, one possible way is to handle the CellPainting event to draw a "+" or "-" icon on the row header, handle the CellClick event to expand the current row to use another DataGridView to show the child records. But I am afraid it will cost you a lot of time.

    Hope this helps.
    Best regards.
    Rong-Chun Zhang

    Saturday, February 02, 2008 7:55 AM

All replies

  •  

    Hi jeeban,

    The DataGridView does not have build-in support for displaying master/detail data in one DataGridView. You still can use this DataGrid control if it meets your needs; the DataGrid is still supported in .Net FrameWork 2.0.

    It is recommended you use two DataGridViews to show the master/detail data; one for the master table and the other for the details table. Here is a sample for your reference.

    ·         How to: Create a Master/Detail Form Using Two Windows Forms DataGridView Controls
    http://msdn2.microsoft.com/en-us/library/c12c1kx4.aspx

    If you still want to show this kind of data in one DataGridView like the DataGird does, one possible way is to handle the CellPainting event to draw a "+" or "-" icon on the row header, handle the CellClick event to expand the current row to use another DataGridView to show the child records. But I am afraid it will cost you a lot of time.

    Hope this helps.
    Best regards.
    Rong-Chun Zhang

    Saturday, February 02, 2008 7:55 AM
  • Thnaks Rong-Chun Zhang
    i have done what u told.
    it is working fine. i m showing the child datagrid when clicking the dataheader.
    but can not get how to add the "+" icon in the cell painting event .

    Monday, February 04, 2008 7:25 AM
  •  

    Have you tried this?

     

    DataGridView1.Rows.Item(Index).HeaderCell.Value = "+"

    DataGridView1.Rows.Item(Index).HeaderCell.Value = "-"


     

    Monday, February 04, 2008 7:47 PM