DataGridView cell formatting after data binding

Source: Internet
Author: User
Tags microsoft website

Microsoft website

After DataGridView data binding, it is often necessary to convert the data into some format, say 1 for men and 2 for females.

At this point, you need to use the Cellformatting event

Here's an example of Microsoft's official

Private void datagridview1_cellformatting (object sender,  Datagridviewcellformattingeventargs e) {    // if the column is  the Artist column, check the    // value.     if  (This.datagridview1.columns[e.columnindex]. name ==  "Artist")     {        if  (E . Value != null)         {             // Check for the string  "Pink"  in the  cell.            string stringvalue  =  (String) e.value;             Stringvalue = stringvalue.tolower ();             if  ((Stringvalue.indexof ("Pink")  > -1)              {                 e.CellStyle.BackColor = Color.Pink;             }        }    }     else if  (This.datagridview1.columns[e.columnindex]. name ==  "Release date")     {         shortformdateformat (e);     }}


DataGridView cell formatting after data binding

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.