2012-06-18 22 views
0

我想知道每次有人檢查datagridview的複選框時是否有事件發生。c#datagridview的checkedbox有沒有事件

我的目標是統計檢查了多少行,但我希望每次用戶檢查時刷新計數,所以這就是爲什麼我想知道是否有每個檢查您的用戶的事件。 (就像在正常的複選框,checkBox_CheckedChanged)

謝謝

+0

你需要調用gridview的命令事件裏面的datagridview的子元素。 –

回答

2

沒有沒有(據我所知),但你可以使用這個簡單的解決方法:

private void dgAreas_CellContentClick(object sender, DataGridViewCellEventArgs e) 
{ 
    IsChecked = (bool)dgAreas[e.ColumnIndex, e.RowIndex].EditedFormattedValue 
    ... 

} 

你有收聽CellContentClick事件。

0

試試這個:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { 
    //Closing current edited cell (for prevent problems) 
    this.dataGridView1.EndEdit(); 
    //Retrive the datasource from the gridView in a DataTable (in this case, i use a DataSource with Visual Studio Wizard 
    DataTable source = ((DataSet)((BindingSource)this.dataGridView1.DataSource).DataSource).Tables[0]; 
    //The magic code line ("IdCierre is my checkeable field" in the grid). I use Linq 
    this.label_contador.Text = source.AsEnumerable().Where(x => x.Field<bool>("IdCierre") == true).Count().ToString(); 
}