Extended functions of the datagridview (3)

Source: Internet
Author: User

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

 

 

 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.