Adding row headings to DataGridView controls in Winform

Source: Internet
Author: User

There are a number of ways.

1, can be in DataGridView control in the rowstatechanged event changes the value of the row header cell (Row.HeaderCell.Value)

1         /// <summary>2         ///occurs when a row state changes3         /// </summary>4         /// <param name= "Sender" ></param>5         /// <param name= "E" ></param>6         Private voidDatagridview1_rowstatechanged (Objectsender, DataGridViewRowStateChangedEventArgs e)7{
8 //E.row.headercell.value = string. Format ("{0}", E.row.index + 1);9E.row.headercell.value = (E.row.index +1). ToString ();//Add line numberTen}

2. The rowpostpaint Event Example can be set in the DataGridView control, and theDrawText () method of the TextRenderer class uses the specified device context, font, The color and format description draws the specified text in the specified bounds.

1         /// <summary>2         ///occurs when a row is drawn when all cells are drawn3         /// </summary>4         /// <param name= "Sender" ></param>5         /// <param name= "E" ></param>6         Private voidDatagridview1_rowpostpaint (Objectsender, Datagridviewrowpostpainteventargs e)7         {8             //9System.Drawing.Rectangle Rectangle =NewRectangle (e.rowbounds.location.x, E.rowbounds.y, This. Datagridview1.rowheaderswidth-4, This. datagridview1.columnheadersheight);TenTextrenderer.drawtext (E.graphics, (E.rowindex +1). ToString (), This. DataGridView1.RowHeadersDefaultCellStyle.Font, Rectangle, This. DataGridView1.RowHeadersDefaultCellStyle.ForeColor, Textformatflags.verticalcenter | Textformatflags.right);//"Textformatflags.verticalcenter | Textformatflags.right "in" | " Has an added effect, two text character formatting styles are added here One}

Adding row headings to DataGridView controls in Winform

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.