delphidelphi-xe2sybase-asa

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.


Solution

  • 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.