DatagridView Not Displaying the error icon or erro

2020-08-09 10:43发布

问题:

I have a win form (c#) with a datagridview. I set the grid's datasource to a datatable.

The user wants to check if some data in the datatable exists in another source, so we loop through the table comparing rows to the other source and set the rowerror on the datatable to a short message. The datagridview is not showing these errors. The errortext on the datagridviewrows are set, but no error displayed.

Am I just expecting too much for the errors to show and they only show in the context of editing the data in the grid?

I have been tinkering with this for a day and searched for someone that has posted a simalar issue to no avail - help!

回答1:

Check that AutoSizeRowsMode is set to DataGridViewAutoSizeRowsMode.None. I have found that the row Errortext preview icon is not displayed when AutoSizeRowsMode is not set to the default of none.

DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None


回答2:

This is a bit late for the original poster, but here what solved it for me...

Check the row height. If it's less than 19 it will not draw the icon. Try setting it a bit higher to see if thats the problem.

grid.RowTemplate.Height = 22


回答3:

If you set e.Cancel to True the icon does not display. Which does not let the user know that a problem exists on that line.



回答4:

The DataGridView has to be visible at the time the ErrorText property is set.



回答5:

One more reason the error icon is not showing is, if the row header size is too small. By default, it is 46. If for some reason you set the row header to a smaller size, such as 30, the error icon will not display.



回答6:

If you are using Visual Studio 2017 and your data is not bound to a datasource, then you have to set the ErrorText on the cell rather than the row, like this:

gvwWebsites.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "You have already used that address.";


回答7:

I experienced similar issue when validating user input in the

private void gridGrid_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)

handler. The problem was I set e.Cancel=true in case of invalid input.



回答8:

Check dgv.ShowRowErrors property.



回答9:

In case someone else is still searching nowadays: The solution that worked for me was to re-assign the (same) DataSource to the DataGridView, and call the Refresh method on the grid after having set the RowError properties.

(VB.Net code:)

myDataGridView.DataSource = myDataSet.Tables(0) 
myDataGridView.Refresh()

After doing that, the newly assigned RowError's were finally displayed.



回答10:

I believe that the errors will only show on editing. What you could do is add a bool column to your DataTable, which drives the display of an image/custom column in the DataGridView, reflecting whether there is an error or not.



回答11:

Send an ESC keystroke will force it to show (at least worked for me)

SendKeys.Send("{ESC}");