ChrisChuah 0 Posted August 4, 2022 Hi When the database table is updated and i use dbgrid.datasource.dataset.refresh, the dbgrid is refreshed back to the first row. Is it possible to refresh the grid without going back to the first row? This is because if there is frequent update to the database and this Refresh notification is sent to my app each time another app updates the table, the dbgrid will always move back to the first row when it is refreshed. Any advise regards chris Share this post Link to post
Stano 143 Posted August 4, 2022 It also depends on DB. One solution is to save the primary key of the current record. After refresh use it in Locate() Share this post Link to post
ChrisChuah 0 Posted August 4, 2022 If there is frequent update to the table, then the user will see the table moving up and down (always locating the record) isnt it? will this (record pointer moving up and down on the grid) happen? Share this post Link to post
Attila Kovacs 629 Posted August 4, 2022 34 minutes ago, ChrisChuah said: then the user will see the table moving up and down dataset.disablecontrols; / dataset.enablecontrols; Share this post Link to post
ChrisChuah 0 Posted August 4, 2022 hi ok i will try it with the locate function for the disablecontrols and enablecontrols thanks chris Share this post Link to post
Hans J. Ellingsgaard 21 Posted August 4, 2022 The client dataset has a bookmark method you can use. Also use dataset.disablecontrols; / dataset.enablecontrols before and after refresh, as Attila suggests, to avoid flickering in the dbgrid. Share this post Link to post
Lajos Juhász 293 Posted August 4, 2022 https://stackoverflow.com/questions/849568/how-long-does-a-tdataset-bookmark-remain-valid Answer from Jeroen Wiert Pluimers: Like both c0rwin and skamradt already mention: the bookmark behaviour depends on the TDataSet descendant you use. In general, bookmarks become invalid during: close/open refresh (on datasets that support it) data changes (sometimes only deletions) I know 1. and 2. can invalidate your bookmarks in TClientDataSets. I am almost sure that for TClientDataSets it does not matter which underlying provider is used (TSQLQuery, TIBQuery, etc). The only way to make sure what works and what not is testing it. Which means you are totally right in not using them: bookmarks have an intrinsic chance of being unreliable. To be on the safe side, always call BookmarkValid before going to a bookmark. Share this post Link to post
ChrisChuah 0 Posted August 5, 2022 hi i have tried using gotobookmark on TQuery with TClientDataset and it could not work. Will try to use the locate function. thanks Share this post Link to post
ChrisChuah 0 Posted August 10, 2022 Thanks. need to use locate with disable/enable controls so that the table will not have moving effect. However, for my dataset, it has 50 columns but the dbgrid can only show first 10 columns on the screen. If need to show next 10 columns, i will need to scroll to the next 10 columns. So, when i am looking at the next 10 columns and the table refreshed, can the refresh go to the next 10 columns rather than always go back to the 1st 10 columns? regards cris Share this post Link to post
Lajos Juhász 293 Posted August 10, 2022 You can read the protected leftcol property of the grid: type TCrackDBGrid = class(TDBGrid); TCrackDBGrid(DBGrid1).LeftCol will return the first column of the screen. Share this post Link to post