[SOLVED] Query, keep selected record after refresh

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
vejrous
Junior Boarder
Junior Boarder
Posts: 27
Joined: 19.02.2017, 21:33

[SOLVED] Query, keep selected record after refresh

Post by vejrous »

Is there a way to force Query to keep selected record after refresh (based on primary key)?
Now it seems, that when any avalue is changed, first record is selected (I understand this must be the case when current record is deleted).
Last edited by vejrous on 04.08.2018, 20:53, edited 1 time in total.
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Query, keep selected record after refresh

Post by marsupilami »

Hello,

what kind of refresh are you talking about? usually the selected record doesn't change after an edit - post cycle?
Best regards,

Jan
vejrous
Junior Boarder
Junior Boarder
Posts: 27
Joined: 19.02.2017, 21:33

Re: Query, keep selected record after refresh

Post by vejrous »

Well, I have 3 tables: "Status", "Status_Subject" and "Subject".
"Status_Subject" is just linking table betwean the other two.

There is a grid, that shows Status + all Subjects assigned to status.

So when I add subject, list needs to be refreshed, but because column with subjects changes, first item is selected.
Maybe it is not meant to be used like this and there is a proper better way?

List SQL:

Code: Select all

SELECT
  ID,
  Status,
  Group_Concat(Subject.Name SEPARATOR ', ') AS Subjects
FROM
  Status
LEFT JOIN
  Status_Subject ON Status.ID = Status_Subject.StatusID  
LEFT JOIN
  Subject ON Status_Subject.SubjectID = Subject.ID
GROUP BY
  JobStatus.ID
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1956
Joined: 17.01.2011, 14:17

Re: Query, keep selected record after refresh

Post by marsupilami »

Hello vejrous,

TZQuery.Refresh more or less works like Close + Open. This might be the reason why the first record is selected afterwards.Maybe you want to do something like this:

Code: Select all

procedure RefreshMyQuery;
var
  CurrentID: Integer;
begin
  MyQuery.DisableControls;
  try
    CurrentId := MyQuery.FieldByName('ID').AsInteger;
    MyQuery.Refresh;
    MyQuery.Locate('ID', CurrentId, []);
  finally
    MyQuery.EnableControls;
  end;
end;
Best regards,

Jan
vejrous
Junior Boarder
Junior Boarder
Posts: 27
Joined: 19.02.2017, 21:33

Re: Query, keep selected record after refresh

Post by vejrous »

Thank you for help.
Post Reply