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).
[SOLVED] Query, keep selected record after refresh
[SOLVED] Query, keep selected record after refresh
Last edited by vejrous on 04.08.2018, 20:53, edited 1 time in total.
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Re: Query, keep selected record after refresh
Hello,
what kind of refresh are you talking about? usually the selected record doesn't change after an edit - post cycle?
Best regards,
Jan
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
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:
"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
-
- Platinum Boarder
- Posts: 1956
- Joined: 17.01.2011, 14:17
Re: Query, keep selected record after refresh
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:
Best regards,
Jan
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;
Jan
Re: Query, keep selected record after refresh
Thank you for help.