本文介绍了如果取消选中复选框,如何更改datagridview行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 亲爱的先生, 我想更改未选中datagridviewcheckboxcell的datagridviewrow的颜色。请帮助。我用c#.net 我尝试过: private void dataGridView1_CellClick( object sender,DataGridViewCellEventArgs e) { bool b; if (dataGridView1.Columns [ 0 ]。名称== *) { for ( int i = 0 ; i < ; dataGridView1.Rows.Count - 1 ; i ++) {b = Convert.ToBoolean(dataGridView1.Rows [i]。单元格[ *]。Value.ToString()); if (b == false ) { dataGridView1。行[I] .DefaultCellStyle.BackColor = Color.Red; } } } 解决方案 使用 CellContentClick 活动 private void dataGridView1_CellContentClick( object sender,DataGridViewCellEventArgs e) { if (dataGridView1.Columns [e.ColumnIndex] .Name == *) { bool flag =( bool )dataGridView1.Rows [e.RowIndex ] .Cells [e.ColumnIndex] .EditedFormattedValue; if (flag) dataGridView1.Rows [e.RowIndex] .DefaultCellStyle.BackColor = Color.Red; else dataGridView1.Rows [e.RowIndex] .DefaultCellStyle.BackColor = Color.White; } } dear sir,i want to change the color of a datagridviewrow where a datagridviewcheckboxcell is unchecked. plz help. i use c#.netWhat I have tried:private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { bool b; if (dataGridView1.Columns[0].Name == "*") { for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { b = Convert.ToBoolean(dataGridView1.Rows[i].Cells["*"].Value.ToString()); if(b==false) { dataGridView1.Rows[i].DefaultCellStyle.BackColor=Color.Red; } }} 解决方案 use CellContentClick Event private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Columns[e.ColumnIndex].Name == "*") { bool flag = (bool)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue; if (flag) dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red; else dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White; } } 这篇关于如果取消选中复选框,如何更改datagridview行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-03 05:01