Hello i have problem when multiple click in a cells fire out the system event CellContentClick.
When a checkbox is true an amount have to be sum to the cell under the header called "Monto" and when is unchecked the amount have to be substracted.
Everything goes fine if the user do the click in a slowly way, but if he does rapidly the amount goes crazy. How to handle this situation? I tried to make the cell readonly iniside of the event but didn't work.
Here is a picture of the data grid view
Here is my code of the events handler
private void comissionsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (employeeComissionsDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].IsInEditMode)
{
employeeComissionsDataGridView.CellContentClick -= new DataGridViewCellEventHandler(comissionsDataGridView_CellContentClick);
double amountOfDay = employeeOperations.comissionsEmployeeGetAmount(employeeComissionsDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString(), (e.ColumnIndex - 3).ToString());
double amount = 0;
try
{
amount = Double.Parse(employeeComissionsDataGridView.Rows[e.RowIndex].Cells[35].Value.ToString());
}
catch
{
amount = 0;
}
if (employeeComissionsDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "True")
{
amount += amountOfDay;
employeeComissionsDataGridView.Rows[e.RowIndex].Cells[35].Value = amount;
}
else
{
amount -= amountOfDay;
if (amount < 0) //Decimals handle
amount = 0;
employeeComissionsDataGridView.Rows[e.RowIndex].Cells[35].Value = amount;
}
employeeComissionsDataGridView.CellContentClick += new DataGridViewCellEventHandler(comissionsDataGridView_CellContentClick);
}
}
private void employeeComissionsDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (employeeComissionsDataGridView.IsCurrentCellDirty)
{
employeeComissionsDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}