Refresh a datagrid

  • Thread starter Thread starter Cat
  • Start date Start date
C

Cat

If you have a datagrid with an underlying dataset and rows are added to the
dataset during a program run, how do you get the datagrid to update itself
to repflect the changes in the underlying dataset? I've tried Update() and
Refresh() but these don't seem to work. Only thing that works is rebinding
the datset to the datagrid control, but this doesn't seem to be quite right.

Cat
 
Cat,

What are you binding the data grid to? Are you binding to the table, or
to the data set? It seems like the view you have on the table is different
from what you are modifying.
 
Have you comitted the new data [AcceptChanges], the datagrid may be
excluding the 'Added' RowState rows that you have just added.
 
Nicholas Paldino said:
Cat,

What are you binding the data grid to? Are you binding to the table, or
to the data set? It seems like the view you have on the table is different
from what you are modifying.

Hi

Basically I have a DataSet containing one DataTable. The DataGrid has the
DataTable as it's data source. I've done this at design time. During loading
of the form that the DataGrid is on, rows are added to the DataTable.
However, these aren't reflected in the DataGrid until I set the DataTable to
be it's source (again, although this has already been done at design time).
I need to know the correct procedure for updating my DataGrid, rather than
setting it's data source to null then to the DataTable again. This certainly
works, but I'm not sure it's the correct way of doing it (correct me if I'm
wrong).

Thanks for your help.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Cat said:
If you have a datagrid with an underlying dataset and rows are added to the
dataset during a program run, how do you get the datagrid to update itself
to repflect the changes in the underlying dataset? I've tried Update() and
Refresh() but these don't seem to work. Only thing that works is rebinding
the datset to the datagrid control, but this doesn't seem to be quite right.

Cat
 
Colin Stutley said:
Have you comitted the new data [AcceptChanges], the datagrid may be
excluding the 'Added' RowState rows that you have just added.

I have tried calling AcceptChanges on my DataTable then calling Refresh on
my DataGrid but this doesn't seem to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top