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)
Active1 year, 10 months ago
Bind C# Data GridView component to hierarchical data for data grid in Windows Forms Applications. Jul 31, 2008 - It allows us to display related data in a hierarchical form (a tree!), but I needed it to be sortable and support data binding. The HierarchicalGrid.
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,6671717 gold badges7676 silver badges142142 bronze badges
Yes this can be done.
Set a data relation, either in the dataset designer or in code between the two tables using the foreign key - parent key columns.
![]()
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
Not the answer you're looking for? Browse other questions tagged c#.netdatagridviewexpand or ask your own question.
Master Grid Setting: In Form load I have called this method to create a master DataGridView at runtime.
In my code I add the comments before each line to explain its use.
Hierarchical Datagridview
Cell Click Event: I have called this above method to create a Cell click event for master DataGridView.
This event will be used for the master grid Image click event. In this Event i will get the Order No and filter the result from DataTabledetail .Display the final Dataview result to Detail DataGridView.
In cell click event if the image column is clicked. I will change the image to Expand and Collapse depends on the selected image name.
If the image is selected to Expand then I will make visible of the detail DataGridView.
In cell click event I will get for the current selected Order No. This order No will be used in “DataView” to filter only the selected order result. The Final result will be bind to the Detail DataGridView.
Detail Grid Setting: In Form load I have called this method to create a Detail DataGridView at runtime.
In my code I add the comments before each line to explain its use.
Detail Grid Cell Click Event: I have called this above method to create a Cell click event for Detail DataGridView.
This event will be used for the Detail grid Cell Click Event. In cell click of Detail grid i will get the each cell text and display in the Messagebox. Points of Interest
This program explains the basic functions to create single level Hierarchical DataGridView. This same functionality can be used to create multi level Hierarchical DataGridView.
Datagridview Hierarchical DataHistory
Version 1.0 - > 2014-12-02.
Hierarchical Datagridview In Vb.netComments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |