Domanda

i would like to know if there is an event for every time someone checks an datagridview's checkbox.

My goal is to count how many rows are checked but i want the count to be refreshed every time the user checks, so that is why i'm am wondering if there is an event for each check the user you do. (Just like in the normal checkbox, checkBox_CheckedChanged)

Thank you

È stato utile?

Soluzione

No there isn't (as far as I know), but you can use this simple workaround:

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

}

You have to listen to the CellContentClick event.

Altri suggerimenti

Try this:

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();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top