Search code examples
delphidelphi-xe7tdbgrid

How do I refresh a TDBGrid?


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)


Solution

  • The only code that is needed here is:

    myDbGrid.DataSource.DataSet.Refresh; 
    

    Everything else is redundant in this particular case.