Page 1 of 1

[SOLVED] Query, keep selected record after refresh

Posted: 27.07.2018, 12:29
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).

Re: Query, keep selected record after refresh

Posted: 28.07.2018, 10:48
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

Re: Query, keep selected record after refresh

Posted: 29.07.2018, 20:56
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

Re: Query, keep selected record after refresh

Posted: 29.07.2018, 21:53
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

Re: Query, keep selected record after refresh

Posted: 04.08.2018, 20:52
by vejrous
Thank you for help.