您的位置:首页 > 其它

实现DataGridView控件中CheckBox列的使用

2014-01-20 11:56 429 查看
最近做WindowsForms程序,使用DataGridView控件时,加了一列做选择用,发现CheckBox不能选中。搜索后,要实现DataGridView的CellContentClick事件,将代码贴一下:

1 /// <summary>
2 /// 实现DataGridView控件中CheckBox列的使用
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 private void dgvTradList_CellContentClick(object sender, DataGridViewCellEventArgs e)
7 {
8 if (e.ColumnIndex == 0 && e.RowIndex != -1)
9 {
if ((bool)dgvTradList.Rows[e.RowIndex].Cells[0].EditedFormattedValue == true)
{
dgvTradList.Rows[e.RowIndex].Cells[0].Value = false;
}
else
{
dgvTradList.Rows[e.RowIndex].Cells[0].Value = true;
}
}
19 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: