C# DataGridView中CheckBox的事件触发。

spade24 2010-10-15 08:45:25

比如C# DataGridView 里有两列CheckBox 如何在CellContentClick事件中去判定其中一列的事件:


private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewColumn column = this.dataGridView1.Columns[e.ColumnIndex];
if(column is DataGridViewCheckBoxColumn)//所有CheckBox列
{

}
}



上面是所有列的CheckBox都包括进去了的。
...全文
1013 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengyuananan 2010-10-15
  • 打赏
  • 举报
回复
7 楼正解,,,
wuyq11 2010-10-15
  • 打赏
  • 举报
回复
private void DataGridView1_CellValueChanged(
object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 &&
DataGridView1.Columns[e.ColumnIndex].ValueType == typeof(bool))
{}
}
spade24 2010-10-15
  • 打赏
  • 举报
回复


真的么有人知道吗?
spade24 2010-10-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ly_longyue 的回复:]
根据列号
[/Quote]

是向下面这样吗?

int currentRowIndex = this.dataGridView1.CurrentRow.Index;//选中的当前行

DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)this.dataGridView1.Rows[currentRowIndex].Cells["Column1"];//Column1列是CheckBox


可是,比如我现在“Column1”和“Column2”两列都是CheckBox,用上面代码后,我在“Column2”列上的CheckBox点击,它也会响应事件的,而我现在只想它在“Column1”响应

yoyo_fan_503 2010-10-15
  • 打赏
  • 举报
回复
等待。
龍月 2010-10-15
  • 打赏
  • 举报
回复
根据列号
qiuxin425 2010-10-15
  • 打赏
  • 举报
回复
收藏了
spade24 2010-10-15
  • 打赏
  • 举报
回复


没有人知道吗?

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧