1 private void LoadData() 2 { 3 DataTable tblDatas = new DataTable(); 4 tblDatas.Columns.Add("ID", Type.GetType("System.Int32")); 5 6 tblDatas.Columns.Add("Name", Type.GetType("System.String")); 7 tblDatas.Columns.Add("Version", Type.GetType("System.String")); 8 tblDatas.Columns.Add("Age", Type.GetType("System.String")); 9 tblDatas.Rows.Add(new object[] { 1, "a", "b", "12" }); 10 tblDatas.Rows.Add(new object[] { 2, "a", "b", "15" }); 11 tblDatas.Rows.Add(new object[] { 3, "a", "b", "30" }); 12 tblDatas.Rows.Add(new object[] { 4, "a", "b", "25" }); 13 tblDatas.Rows.Add(new object[] { 5, "a", "b", "30" }); 14 15 dataGridView1.DataSource = tblDatas; 16 } 17 18 private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) 19 { 20 if (e.RowIndex > -1) 21 { 22 int intGrade = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells["dgvAge"].Value); 23 if (intGrade ==30) 24 { 25 dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; 26 } 27 else if(intGrade==25) 28 { 29 dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Brown; 30 } 31 } 32 } 33 --------------------- 34 作者:大米11 35 来源:CSDN 36 原文:https://blog.csdn.net/wk125570/article/details/78026923?utm_source=copy 37 版权声明:本文为博主原创文章,转载请附上博文链接!