[一篮饭特稀原创,转载请注明出自 ChangBackColor()
 2 {
 3     if (dataGridView1.Rows.Count > 0)
 4     {
 5         foreach (DataGridViewRow row in dataGridView1.Rows)
 6         {
 7             if (row.Cells["列名"].Value.ToString() == "条件")
 8             {
 9                 row.Cells["列名"].Style.ForeColor = System.Drawing.Color.Red;
10                 row.DefaultCellStyle.ForeColor = Color.Red; //改变整行的
11             }
12         }
13         DataGridViewCellStyle dgvcs = new DataGridViewCellStyle();
14         dgvcs.BackColor = Color.Green;
15         dataGridView1.Columns["列名"].DefaultCellStyle = dgvcs;  //整列
16     }
17 }

 

相关文章: