views:

41

answers:

2

I have a datagridview on a form that is bound to a table in a dataset from another class.

I use a data adapter to .Fill a table in that dataset and the grid displays the data fine.

Works fine.

On my form I have a textbox the user can type in that will will pass a parameter to the storedprocedure used to fill this table. So on startup the textbox will have "%" in it. and then the user can type in "F%" and get everything that starts with an "F"

So when that textbox changes I launch an async refresh (.BeginInvoke) to do my refresh. The table gets populated with the reduced number of records (I check ds.table(0).rows.count and it is correct)

But the datagridview then starts throwing datagridview.dataerror events. "System.IndexOutofRangeException : Index # does not have a value"

It looks like the dataset is getting filled correctly and not having any issues, but the datagrid is not liking this update. The index out of range error is so common that I'm not finding what I need through searches.

Thanks in advance! :)

A: 

Well, find the error.

  • Take out the BeginInvoke and do it synchronous. See if that fixes it. If not, leave it out until you're sure you have no other problems.

  • @roadie has a good comment on resetting the SelectedRow

  • There are similar ways to enforce the update. Like

..

   bindingSource.DataSource = null; 
   bindingSource.DataSource = myTable;
Henk Holterman
Gotcha... Yeah I had the same issue without the async call, but I tried assigning the .DataSource to nothing and then putting it back after the refresh has called back and that seemed to do it. I may go back and check the currently selected row as well.
BTT
+1  A: 

I don't know the solution to your specific problem, but it seems like a waste to hit the database for every keystroke when all the data is loaded up front.

Rather than requerying the database every time, why not set the RowFilter of the DataView and skip the database call?

whatknott