Selected row centers itself after query refresh

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Draner
Posts: 4
Joined: Fri 13 Oct 2017 15:26

Selected row centers itself after query refresh

Post by Draner » Fri 13 Oct 2017 15:40

Hello,

I have a small software that uses a dbgrid. The problem is that when we refresh our MSQuery with the help of a MSChangeNotification the row that is currently selected in the dbgrid is centered if possible. This can be a bit annoying when we are scrolling down with the arrow keys, and that the db is updated every second or so. Is there a way to not center the active row? (Before SDAC we used FireDAC and the problem was not present, so it's probably not the grid's fault)

Thanks

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Selected row centers itself after query refresh

Post by azyk » Wed 18 Oct 2017 13:43

In order for SDAC not to reopen dataset when receiving a notification, set TMSQuery.Options.ReflectChangeNotify to False. More details about ReflectChangeNotify in our online documentation: https://www.devart.com/sdac/docs/?devar ... notify.htm

You can refresh data in dataset without its reopening by calling the TMSQuery.RefreshQuick method: https://www.devart.com/sdac/docs/?devar ... olean).htm

Draner
Posts: 4
Joined: Fri 13 Oct 2017 15:26

Re: Selected row centers itself after query refresh

Post by Draner » Mon 23 Oct 2017 13:58

Firstly, thank you for the response.

I tried with refresh quick but it only seems to work once. It's like if the query was not registered to be notified after the first refresh. In other words, my query update itself once and then it stops refreshing. Is there something you have to set for it to work, or is it because the query doesn't reopen?

Thank you again

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Selected row centers itself after query refresh

Post by azyk » Wed 25 Oct 2017 10:04

As one of the task solutions, before opening dataset, execute the following code:

Code: Select all

  MSQuery1.Options.NonBlocking := True;
  MSQuery1.Options.ReflectChangeNotify := False;
  MSQuery1.ReadOnly := False;
and in the TMSChangeNotification.OnChange event handler, call the Refresh method:

Code: Select all

procedure TMainForm.MSChangeNotification1Change(Sender: TObject;
  DataSet: TCustomMSDataSet; NotificationInfo: TMSNotificationInfo;
  NotificationSource: TMSNotificationSource;
  NotificationType: TMSNotificationType);
begin
  ...
  MSQuery1.Refresh;

Draner
Posts: 4
Joined: Fri 13 Oct 2017 15:26

Re: Selected row centers itself after query refresh

Post by Draner » Wed 25 Oct 2017 13:49

I just tried it and it still centers my active row.

Would it be possible to get an example of a working RefreshQuick?

Thank you

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Selected row centers itself after query refresh

Post by azyk » Tue 31 Oct 2017 15:13

Please specify whether the specified issue is reproduced on our SDACDemo project. Use the solution from my previous post. SDACDemo project is located in the folder "Demos\SDacDemo\" relatively the path where SDAC demo projects were installed.

If the specified issue is not reproduced on SDACDemo, then compose a small test project to demonstrate it and to us via the contact form at our site: https://www.devart.com/company/contactform.html . Also include test DB backup(BAK) to the project.

Draner
Posts: 4
Joined: Fri 13 Oct 2017 15:26

Re: Selected row centers itself after query refresh

Post by Draner » Wed 01 Nov 2017 14:05

I was able to reproduce the issue in the demo. I needed to had a bunch of data in the table so that the row could centers itself.
Here is how it looks before the update: https://imgur.com/SMY6Pqk
And here is the result after: https://imgur.com/a0MBwb9

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Selected row centers itself after query refresh

Post by azyk » Mon 06 Nov 2017 08:19

We cannot affect the position of the active record in the grid when calling TMSQuery.Refresh/RefreshQuick, because SDAC datasets cannot control the behavior of the visual controls. To solve the issue, please read the documentation of the visual components that you are using either the specialized forums.

Post Reply