Now that we have just about enough information to get an idea of what the problem is ...
You have put this code in the CellValidated event which
Quote:
"Occurs after the cell has finished validating."
to quote the text that appears in the properties window when you highlight that event.
Try putting the validation in the CellValidating event where e.Cancel
will be available to you
[Edit] Attempting to make it clearer ...
private void dgvItemDetails_CellValidated(object sender, DataGridViewCellEventArgs e)
{
}
private void dgvItemDetails_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (Convert.ToString(dgvItemDetails["QTY", e.RowIndex].Value).Contains("-."))
{
MessageBox.Show(this, "Please enter proper numeric value.", "Error Caption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
e.Cancel = true;
return;
}
}