C#DataGridView的CheckBox问题

来源:百度知道 编辑:UC知道 时间:2024/05/22 17:12:38
DataGridView中有两列,第一列是一个CheckBox,第二列任意,要实现点击任意一行的单元格,该行的CheckBox被选中,再单击一次,CheckBox选中取消。
注:*DataGridView刚加载时光标在第一行但是CheckBox不选中。
谢谢!
下面两个都不正确啊
还请大家踊跃回答啊
答对的会加分的

写在cell_click事件里面
//假设第一个列为选择列
if(e.rowindex>-1&&e.columindex>-1)
{
if(this.dataGridView1.Rows[e.RowIndex].Cells[0].EditedFormattedValue.ToString()= = "True")
{
this.dataGridView1.Rows[e.RowIndex].Cells[0].EditedFormattedValue = "False";
}
else
{
this.dataGridView1.Rows[e.RowIndex].Cells[0].EditedFormattedValue = "True";
}
}