Sharpie
Sharpie

Reputation: 383

Refresh Query / cxGrid

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

Answers (3)

Alexander84
Alexander84

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

MrRobot
MrRobot

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.

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/DB_TDataSet_GetBookmark.html

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

crefird
crefird

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

Related Questions