Search code examples
c#.netdatagridviewexpand

Win Forms DataGridView - showing hierarchical parent/child rows


I am trying to construct a datagridview that will show a number of rows with a particular set of fields, but also allow me to show some 'subrows' ie rows that can be expanded below the parent row in question (if that parent row has these children - part of the datasoruce) the only real problem is that the expanded rows will have completely different fields(columns)

is this possible with a standard datagridview in a windows form? I am presuming somehow I would have to shoehorn in a new datagridview in a row of the parent grid.

We do have the Syncfusion suite which includes the gridgroupingcontrol. but after much hair pulling and other pains. I have given up on that completely.


Solution

  • Short answer: No. You need a custom component for this.

    There are a lot of good efforts out there on making a hierarchical treeview. Like in the CodeProject article TreeView with Columns or FlexGrid from Component One (paid). I understand you want different fields on the subnodes though, and I'm unsure to what extent these controls support that. I know FlexGrid support some customization of columns for different rows, but it will probably involve quite some manual work - databinding is not well supported.

    Finally, you might want to consider if your idea of a customized GridView is the best approach to your problem in the first place. Could a Master-Detail-view be a better approach?

    PS: I'm not affiliated with ComponentOne, but I've used FlexGrid in a project.