The National Day holiday is so fast. I really hope I can ........ (Hello, wake up ...)
The following shows the group display of the DataGrid.
In fact, this is not difficult, because the datagridview has provided many functions. We only need to encapsulate some functions.
For example, grouping is used to control the display and hiding of rows by using an important attribute of the original control, namely, datagridviewrow. visible.
Imagine that when you fold a group, it actually hides its child rows,
When you expand a group, set the visible attribute of all its child rows to true.
After understanding the principle, it is easier to implement it. It is nothing more than controlling the visible attribute of rows and drawing the "plus" and "minus" sign through cell self-painting.
Now, we do not need to modify the datagridviewex class this time, But inherit two new classes from the datagridviewtextboxcolumn and the datagridviewtextboxcell.
They indicate the "column" and "cell" of the datagridview, respectively"
/// <Summary>
/// Grouping columns (this column must be the first column of the grid)
/// </Summary>
Public Class Datagridviewgroupcolumn: datagridviewtextboxcolumn
/// <Summary>
/// Cells that can be grouped
/// </Summary>
Public Class MAID: maid
MainCodeIn datagridviewgroupcell,
Showchild
Painting + and-
The final piece of called code will produce the effect in the image at the beginning of this article after it is run.
Call and run
Code download