1
I’m having a problem with the Datagridview checkbox Cell:
Click on checkbox, and it marks the Checkbox and updates a value field. I click again, and he does the opposite. Everything works normally, until I quickly click on checkbox. Then he gets lost and he doesn’t score anymore, like, the checkbox not marked on the screen, but the value is True.
I have searched other forums, I have even found answers, but none that can correct this problem.
Here is the code:
private void dgvServico_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dgvServico.CurrentRow.Cells["Check"];
if (chk.Value == chk.TrueValue)
{
//chk.Value = CheckState.Unchecked;
chk.Value = chk.FalseValue;
valor -= Convert.ToDouble(dgvServico.CurrentRow.Cells["valorDataGridViewTextBoxColumn"].Value);
txtValorTotal.Text = valor.ToString();
dgvServico.Refresh();
}
else
{
//chk.Value = CheckState.Checked;
chk.Value = chk.TrueValue;
valor += Convert.ToDouble(dgvServico.CurrentRow.Cells["valorDataGridViewTextBoxColumn"].Value);
txtValorTotal.Text = valor.ToString();
dgvServico.Refresh();
}
}
}
Why when receiving the click you do not give an enabled false in the column and at the end of an enabled true, not allowing it to be clicked again until the specified method is executed?
– Marciano.Andrade
Try using lock to prevent more than one event from changing the state at the same time.
– lsalamon