How do I refresh a TDBGrid?

BIBD picture BIBD · Feb 19, 2015 · Viewed 11.8k times · Source

I have a TDBGrid called myDbGrid that I want to update after a change to the database (insert/update/delete). How can I do this without reloading my form completely?

myDbGrid uses myDataSource and it uses myQry as its data set.

I've tried the following with no success:

myDbGrid.Refresh;

and

myDbGrid.DataSource.DataSet.Close;
myQry.Close; // '' I think this is redundant
myQry.Open;
myDbGrid.DataSource.DataSet.Refresh;

What have I missed?

(I'll note that the database change is not happening in the tDBGrid - it's there for display only)

Answer

BIBD picture BIBD · Mar 2, 2015

The only code that is needed here is:

myDbGrid.DataSource.DataSet.Refresh; 

Everything else is redundant in this particular case.