DataGirdView隔行显示颜色

private void Sql操作_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“myDBDataSet5.SYSEVENT”中。您可以根据需要移动或删除它。
this.sYSEVENTTableAdapter3.Fill(this.myDBDataSet5.SYSEVENT);

/*
装载事件
*/
btnConn.Enabled = true;
btnCmd.Enabled = false;
btnUpdate.Enabled = false;
btnDelete.Enabled = false;
btnClose.Enabled = false;
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = 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;
}

//事件触发颜色

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");
}
}

猜你喜欢

转载自www.cnblogs.com/zhongruanzikong/p/11820328.html