views:

628

answers:

1

I have a data collection that holds a list of companies' data. Some companies have more than one office. I want to use windows form's datagridview to represent the data like this:

|--Company Name--|--Company ID--|--Company Address--|

| Alpha          | 001          |  1 Alpha road     |

            |--Office Name---|--Office Address--|

            | London Office  | 1 London road    |

            | New York office| 1 New York road  |

| Beta           | 002          |  1 Beta Road      |

            |--Office Name---|--Office Address--|

            | LA Office      | 1 LA road        |

            | Paris Office   | 1 Paris road     |

I want a company's offices displayed as a child datagridview inside the parent datagridview . I found many solutions in ASP.net, but none in winform. Is there any way to achieve this?

A: 

Not 100% sure this would work, but maybe try something like this?

DataGridView dgv = new DataGridView();
grid.Controls.Add(dgv);
dgv.Location = grid.GetCellDisplayRectangle(ColumnIndex, RowIndex, true).Location;
dgv.Size = grid.GetCellDisplayRectangle(ColumnIndex, RowIndex, true).Size;
Jage
I tried it, but it didn't work.
wschenkai
Sorry, I forgot to mention that you might want to put that code into the painting event so that it draws the control.I just tried it and it seemed to work.
Jage