15.8DataGridView Select rows Display different colors

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespace_15._8datagridview Display different colors { Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        Private voidForm1_Load (Objectsender, EventArgs e) {            //TODO: This line of code loads the data into the table "csharpzxwdataset.mytable001". You can move or delete it as needed.              This. Mytable001tableadapter.fill ( This. csharpzxwdataset.mytable001); }        Private voidDatagridview1_rowprepaint (Objectsender, Datagridviewrowprepainteventargs e) {            if(E.rowindex >= DataGridView1.Rows.Count-1)return; Color Oldforecolor=NewColor (); Color Oldbackcolor=NewColor (); //object is the base class for all classes as reference types            varrow =Datagridview1.rows[e.rowindex]; if(row = = Datagridview1.currentrow)//determine if the line has been manipulated            {                if(Row. Defaultcellstyle.forecolor! =color.white) {Oldforecolor=row.                    Defaultcellstyle.forecolor; Row. Defaultcellstyle.forecolor=Color.White; }                if(Row. Defaultcellstyle.backcolor! =color.blue) {Oldbackcolor=row.                    Defaultcellstyle.backcolor; Row. Defaultcellstyle.backcolor=Color.Blue; }            }            Else{row. Defaultcellstyle.forecolor=Oldforecolor; Row. Defaultcellstyle.backcolor=Oldbackcolor; }        }    }}

15.8DataGridView Select rows Display different colors

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.