Note that there are some explanatory texts on larger screens.

plurals
  1. PODataGridView Validation - remove error indicator
    primarykey
    data
    text
    <p>I'm validating a DataGridView using the following code ...</p> <pre><code>void centreDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (centreDataGridView.Columns[e.ColumnIndex].Name == "code") { Regex codeRegex = new Regex("^[0-9]{5}[0-9A-Z]$"); if (!codeRegex.IsMatch(e.FormattedValue.ToString())) { centreDataGridView.Rows[e.RowIndex].ErrorText = "error text here"; } } } void centreDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { centreDataGridView.Rows[e.RowIndex].ErrorText = string.Empty; } </code></pre> <p>This works, except that if I enter the new row and then leave it again without entering any data, the error warning icon remains visible in the new row selector. How can I clear it?</p> <p>Based on the suggestions received so far, I've modified the above code as follows ...</p> <pre><code>void centreDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (centreDataGridView.Columns[e.ColumnIndex].Name == "code") { if (!(centreDataGridView.Rows[e.RowIndex].IsNewRow) || (e.FormattedValue.ToString() != string.Empty)) { Regex codeRegex = new Regex("^[0-9]{5}[0-9A-Z]$"); if (!codeRegex.IsMatch(e.FormattedValue.ToString())) { centreDataGridView.Rows[e.RowIndex].ErrorText = "error text here"; } } } } </code></pre> <p>This does solve the problem of the error indicator displaying beside the new row when no data has been entered. However, when I enter invalid data, in any row, no error indicator is shown when I move off the row for the first time after entering the invalid data. If I move off the row with the invalid data, then move back to it, then move off it again, then the error indicator is shown.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload