Jump to content
ChrisChuah

DBGrid repaint or refresh when dataset is refreshed

Recommended Posts

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

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

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

hi

ok i will try it with the locate function for the disablecontrols and enablecontrols

 

thanks

chris

 

Share this post


Link to post

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

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:

  1. close/open
  2. refresh (on datasets that support it)
  3. 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

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×