Number and select all columns of the DataGridView Extension Method

Source: Internet
Author: User

[Csharp] /// <summary> /// Add a row number to the DataGridView /// </summary> /// <param name = "dgv"> DataGridView Control ID </param> public static void AddRowIndex (this DataGridView dgv) {dgv. rowPostPaint + = delegate (object sender, DataGridViewRowPostPaintEventArgs e) {SolidBrush B = new SolidBrush (dgv. rowHeadersDefaultCellStyle. foreColor); e. graphics. drawString (e. rowIndex + 1 ). toString (), dgv. defaultCellStyle. font, B, e. rowBounds. location. X + 10, e. rowBounds. location. Y + 4 );};} /// <summary> /// select all for the DataGridView /// </summary> /// <param name = "dgv"> DataGridView Control ID </param> /// <param name = "columnIndex"> sequence number of all columns </param> public static void AddFullSelect (this DataGridView dgdgv, int columnIndex) {if (dgv. rows. count <1) {return;} CheckBox ckBox = new CheckBox (); Rectangle rect = dgv. getCellDisplayRectangle (1,-1, true); ckBox. size = new Size (dgv. columns [1]. width-12, 12); // size Point point = new Point (rect. X + 10, rect. Y + 3); // The position ckBox. location = point; ckBox. checkedChanged + = delegate (object sender, EventArgs e) {for (int I = 0; I <dgv. rows. count; I ++) {dgv. rows [I]. cells [columnIndex]. value = (CheckBox) sender ). checked;} dgv. endEdit () ;}; dgv. controls. add (ckBox );}

Related Article

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.