15
votes

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!

11

11 Answers

10
votes

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
9
votes

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
6
votes

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.

5
votes

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

3
votes

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.";
2
votes

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.

2
votes

Check dgv.ShowRowErrors property.

1
votes

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.

0
votes

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.

-1
votes

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.

-1
votes

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

SendKeys.Send("{ESC}");