0

My users want a way to do mass uploads/edits to our products database, almost as if they were using excel, where they can copy and paste in a spreadsheet. Although this makes me cringe to think about, I am not the boss so it is what it is. I am just going to dump everything to a datagrid view and let them edit it there (ugh). There are many things though that require specific values (ie Size) and I do not want them to enter in XL, XLarge, X-Large, xlarge when they should all be XLarge for example. So I need combo boxes. Easy enough, but they also want to be able to select what columns are going to be displayed, so it isn't a static table that I can just specify column types. I've managed to dynamically make the appropriate columns combobox columns and fill them with data. I fill them like so:

for (int y = 0; y < table.Rows.Count; y++)
{
    viewMassEdit.Rows.Add();
    for (int x = 0; x < table.Columns.Count; x++)
        viewMassEdit.Rows[y].Cells[x].Value = table.Rows[y][x].ToString();
}

All of the data fills correctly. No exceptions. Here's where the problem comes in. This creates a large table, and when I begin to scroll around, vertically or horizontally, these unhandled error messages periodically pop up:

enter image description here

What the crap is it talking about? It accepted the value fine when I put it there, how is it a problem now when I am navigating through the table? Furthermore, where would I go to handle this error?

Nick
  • 1,903
  • 2
  • 21
  • 40

2 Answers2

1

Well, to "handle" the error - add a handler to the event DataGridView.DataError:

void InitializeComponent() {
   // ... //

   this.DataGridView.DataError += this.DataGridView_DataError;
}

void DataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e) {
   e.ThrowException = false;
}

You probably want to debug that DataGridViewDataErrorEventArgs, and see what the exception, etc. is so that you can prevent it from firing in the first place.

Mark Brackett
  • 84,552
  • 17
  • 108
  • 152
  • Thanks for the reply, I may have been misleading with my last sentence. I don't just want to "handle" the error, although it seems like it would work fine either way. I want to do as you said and prevent it from firing. Unfortunately all the DataGridViewDataErrorEventArgs tells me is the same as the error message popup. – Nick Jun 22 '11 at 22:08
  • @Nick - Quick Googling seems to indicate that it's caused by binding a value that doesn't exist in the source. My guess is you have a DBNull in the source data, which is setting to string.Empty. The error pops up, and probably defaults to "Small" or the first of your enumerated values. – Mark Brackett Jun 26 '11 at 22:48
0

To know where to handle the error, debug with Break on Handled Exceptions on (Debug->Exceptions). that should help you pinpoint the source.

therealmitchconnors
  • 2,732
  • 1
  • 18
  • 36
  • I see no such option. I am using VS2010 if that makes a difference. I tried checking the box to break on `System.ArgumentException` but it didn't help. – Nick Jun 22 '11 at 21:23
  • In the exceptions menu, you should see two columns of check boxes, Thrown, and User Unhandled. By default, thrown is false and unhandled is true. Try checking thrown for all CLR Exceptions. – therealmitchconnors Jun 22 '11 at 21:26
  • No luck. I even went ahead and checked every other box as well but it still displays the error message and does not break. – Nick Jun 22 '11 at 22:05
  • I also had no luck with configuring "break on thrown" for these DataGrid default errors. In VS2015, I checked everything in the Exceptions Settings under "break when thrown". All kinds of other exceptions break, but when I get a System.Data.InvalidContraintException (which is explicitly in the list and checked) I still get this stupid dialog and no break point. – Wilbur Whateley May 24 '18 at 20:46