Datagrid not updating after dataset records change

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a datagrid that is bound to a table within a (disconnected) dataset
using .SetDataBinding. When a stored procedure is run, the underlying table
is changed, so I reset the dataset and re-fill the table, loading in the new
values - and I have verified that it has the new data. I then do the
datagrid.SetDataBinding again, and have even refreshed the datagrid, but the
grid remains unchanged and does not show the new values.
 
How are you resetting the dataset? If you call DataTable.Clear on the table
that's bound to the datagrid and then refill it, the changes will show. Is
there any chance that there's a scoping issue and/or you aren't clearing
the datatable so the rows are simply added to the end of the datatable?
 
The whole dataset is being reset by using the .Reset() method. Using
messageboxes, I have verified that the dataset is being repopulated with new
values. I have found a solution, though I am a little concerned with it:
Instead of using the .SetDataBinding (which is recommended at runtime) I
just set the datgrid.DataSource = dataset.Tables("xxx") in code. This is
what I would have tried to begin with if I didn't do any research which all
pointed to the use of .SetDataBinding. Usually I am too dumb, this time I
was too smart!
 
I'm sure someone will correct me if I'm wrong, but .SetDataBinding is
somewhat redundant and can pretty much be avoided. I've never used it and
instead simply bind the dataset(datatable) to the datagrid with no problems
using datagrid.DataSource. Even when you Reset the dataset, you should have
no problem using that technique.
 
Back
Top