我想点击checkbox后触发checkbox_CheckedChanged事件,从网上搜了一下说用EditingControlShowing方法,但好像不好使啊,请问到底用什么方法?我写的代码如下:
this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler
(dataGridView1_EditingControlShowing); void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1 && dataGridView1.CurrentCell.RowIndex != -1)
{
((CheckBox)e.Control).CheckedChanged += new EventHandler(aa_CheckedChanged);
}
} private void aa_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
if (chk.Checked == true)
label1.Text = "你选中了datagridview中的checkbox";
else
label1.Text = "你取消了选中的datagridview中的checkbox";
}
this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler
(dataGridView1_EditingControlShowing); void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1 && dataGridView1.CurrentCell.RowIndex != -1)
{
((CheckBox)e.Control).CheckedChanged += new EventHandler(aa_CheckedChanged);
}
} private void aa_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
if (chk.Checked == true)
label1.Text = "你选中了datagridview中的checkbox";
else
label1.Text = "你取消了选中的datagridview中的checkbox";
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货