Bind C# Data GridView component to hierarchical data for data grid in Windows Forms Applications. Programmatically create a hierarchical grid that displays arbitrary number of child levels.
Active1 year, 10 months ago
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.
demonplus
![]()
4,14799 gold badges3737 silver badges5353 bronze badges
natnat
1,21733 gold badges2626 silver badges4848 bronze badges
3 Answers
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.
NilzorNilzor
![]()
9,6621717 gold badges7676 silver badges142142 bronze badges
Yes this can be done.
Datagridview Hierarchical Data Inserts
Set a data relation, either in the dataset designer or in code between the two tables using the foreign key - parent key columns.
Hierarchical Datagridview In Vb.net
If in the dataset designer, set the nested property to true. This will then give you child records under each parent row in the datagrid view.
demonplus
4,14799 gold badges3737 silver badges5353 bronze badges
Nael MahfouzNael Mahfouz
Deepthi KrishnaDeepthi Krishna
Hierarchy Datagridview C#Not the answer you're looking for? Browse other questions tagged c#.netdatagridviewexpand or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |