DataGridView line data validation: Bug red exclamation point does not appear when the input data is invalid

void dgvView_CellValidating Private (Object SENDER, DataGridViewCellValidatingEventArgs E) 
{
       IF (e.ColumnIndex == 0 &&! dgvView.CurrentRow.IsNewRow) // first determines whether the primary key column null values (excluding new row)
       {
           IF (String.IsNullOrEmpty (e.FormattedValue.ToString ()))
           {
               dgvView.Rows [e.RowIndex] .ErrorText = "primary key column value is not null"; the ErrorText // row is not effective
               e.Cancel = true; // again require modification, still edit mode, the process does not exit, the program to continue
           }
       }
   IF (dgvView.Columns [e.ColumnIndex] .Name == "contactName" && String.IsNullOrEmpty (e.FormattedValue.ToString ()))
       {
            dgvView. Rows [e.RowIndex] .Cells [e.ColumnIndex] .ErrorText = "contactName not recorded"; // entry into force of the cell ErrorText
       }

}

Previous tests when using normal, when the input data is invalid, round red exclamation point icon appears on the title line, the recent pick-up appropriate to revise and improve it and found that the failure to set ErrorText property, life and death do not appear on the row header round red exclamation point icon, the odd strange, how, searched the entire network (including the official website), did not find a solution.

I do not believe this shoe, but fortunately there before the backup version, take over and modified to a eleven than half an hour after finally found, can mad people, has been tested, the key is this one:

dataGridView1.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.None;

DataGridViewAutoSizeRowsMode must is None, appears ErrorText property splats, My God, giant hard shameful, so the key is not in the official website set up specifically noted it, is it a Bug?

Guess you like

Origin www.cnblogs.com/chengyb/p/11388887.html