When I enter some value in a cell in DataGridView and click on another cell the cellvalidating event handler code is executed. Even if validation fills, the cell on which I click gets highlighted. My requirement is that the cell should remain selected and cursor should blink in the cell for editing after removing the invalid value. Am using the below code if the validation fails:
DataGridView1.CancelEdit();
I have tried adding
DataGridView1.CurrentCell.Selected = true;
DataGridView1.BeginEdit(true);
You need to use e.Cancel = true
like below.
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
int i;
if (!int.TryParse(e.FormattedValue.ToString(), out i))
{
e.Cancel = true;
MessageBox.Show("Please input a integral number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments