Group by in Datagrid View
i have a scenario where i have to group the PinCode by city name like one city can have many pincode.
开发者_开发问答I have to do this in winform in datagrid. How can i do this so in datagrid i can see the + and - on before city.
I thing it can be done by nested grid. please, help.
Column A | Column B | Column C
- Country
- Zip Code | 10,00 | 15,00
- Zip Code | 10,00 | 15,00
- Country
- Zip Code | 10,00 | 15,00
- Zip Code | 10,00 | 15,00
Thanks. Shivam
Have you seen the OutlookGrid on CodeProject?
This looks like it will allow you to expand and collapse individual rows as well as control the sort order. Because it extends the built-in DataGridView
control, it even supports data binding!
However, it appears that nested grouping is not currently implemented, although you could look into modifying the source code yourself to add that feature if you decided an alternate presentation of your data is not appropriate.
The DataGridView
control does not support expandable/collapsible rows or nested tables. You will have to use a third party control to achieve this.
Alternatively, have a look at this article, which details how to subclass the existing control. This solution does not support databinding, however, which may limit its usefulness.
The general concept/Logic is that, create a two distinct datatable with of-course at least one common field which is their relations. Then later, add or mix this two datatables in a dataset. Then create a data relation of the two datatable by declaring and initializing a datarelation. lastly, bind it to your Datagridview's datasource.
Use TreeView for grouping data.
精彩评论