DataGirdView interlaced display color

private void Sql operation _Load (SENDER Object, EventArgs E)
{
// the TODO: This line load data into tables "myDBDataSet5.SYSEVENT" in. You may need to move or delete it.
this.sYSEVENTTableAdapter3.Fill (this.myDBDataSet5.SYSEVENT);

/ *
load event
* /
btnConn.Enabled = to true;
btnCmd.Enabled = to false;
btnUpdate.Enabled = to false;
btnDelete.Enabled = to false;
btnClose.Enabled = to false;
Button1 = to false .Enabled;
button2.Enabled = to false;
button3.Enabled = to false;

textBox1.Text ="故障";
textBox2.Text = "231";
textBox3.Text = "321";
textBox4.Text = "123.3";
textBox5.Text = "231.1";
textBox6.Text = "321.1";

//隔行显示颜色
dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightBlue;
dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.White;
}

// event-triggered color

private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex > -1)
{
string Period = this.dataGridView1.Rows[e.RowIndex].Cells["operatorDataGridViewTextBoxColumn"].Value.ToString();
if (Period == "故障")
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;//FromName("#ffffff");
}
else if (Period == "报警")
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Blue;//FromName("#c0c0c0");
}
}

Guess you like

Origin www.cnblogs.com/zhongruanzikong/p/11820328.html