Reputation: 383
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.
Upvotes: 1
Views: 4198
Reputation: 39
for cxgrid of devexpress the bookmaker is a bad solution for restore the selection , you can use the cxStatusKeeper ( it public unit that you can download from support center of devexpress )
{Init the component for restore selection}
FGridStatus := TcxGridDBTableKeeper.Create(self);
FGridStatus.LoadExpanding := False;
FGridStatus.LoadSelection := True;
FGridStatus.LoadFocus := True;
FGridStatus.LoadTopRecord := False;
FGridStatus.LoadWithDetails := False;
FGridStatus.LoadFocusedView := True;
FGridStatus.LoadFocusedItem := True;
FGridStatus.View := gvTableElementi;
{save the current items}
FGridStatus.Store;
{restore the selection}
if FGridStatus.GridStored then
FGridStatus.Restore;
Upvotes: 1
Reputation: 178
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.
Upvotes: 2
Reputation: 1610
cxGridTableView.Navigator
has a Refresh button that will do what you want.
If you want to Refresh using your own button, you can call cxGridTableView.DataController.RefreshExternalData
Upvotes: 0