Using Delphi XE2.
I am writing a software package which uses cxGrids and are linked to Querys/Datasources.
At a click of a button how do you refresh a Query to make sure the records are up to date in the cxGrids.
Also if a record is highlighted on a cxGrid it must remember that record and doesn't reset back to the top of the grid.
Close and open the dataset
behind the cxgrid
to make sure you have the latest data.
dataset.close;
dataset.open;
If you need to remember the current record and put the cursor back on it - use a bookmark as shown in the link below.
If you prefer not to use a bookmark, you can utilise the dataset.locate method. Store the primary key of the record, and after the refresh, use dataset.locate(dataset.fieldbyname('PK').AsDataType) to take you back to that record.
Using the locate method is probably a more readable/elegant way of working.