I'm having a problem with the DataGridView checkBox cell:
Click the checkBox , and it marks the Checkbox and updates a value field. I click again, and it does the opposite. Everything works fine until I quickly click on the checkBox . is not marked on the screen, but the value is set to True.
I looked in other forums, until I found answers, but none that corrects 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();
}
}
}