您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> asp.net编程 >> 正文

实现DataGridView控件中CheckBox列的使用实例

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 最近做WindowsForms程序,使用DataGridView控件时,加了一列做选择用,发现CheckBox不能选中。搜索后,要实现DataGridView的CellContentClick事件,将代码贴一下

代码如下: /// <summary>         /// 实现DataGridView控件中CheckBox列的使用         /// </summary>         /// <param name="sender"></param>         /// <param name="e"></param>         private void dgvTradList_CellContentClick(object sender, DataGridViewCellEventArgs e)         {             if (e.ColumnIndex == 0 && e.RowIndex != -1)             {                 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;                 }             }