Question: The samples you show for using bookmarks work but how do I keep the order of the selections wwDBGrid1.SelectedList now with newer versions of Delphi?
Answer: Unfortunately this is not supported in the grid, but you can accomplish this with a little code in your project. Use the OnMultiSelectRecord and put the following code in it.
procedure TMultiSelectForm.wwDBGrid1MultiSelectRecord(Grid: TwwDBGrid;
Selecting: Boolean; var Accept: Boolean);
begin
if mylist=nil then
mylist:= TList<TBookmark>.create;
mylist.Remove(grid.DataSource.dataset.bookmark);
if selecting then
mylist.add(grid.DataSource.dataset.bookmark)
end;
If you use MultiSelectOptions.msoAutoUnselect then you should also attach the following code to the OnMultiSelectAllRecords so that it detects the auto-unselection. Otherwise mylist will contain the previously auto-unselected record.
procedure TMultiSelectForm.wwDBGrid1MultiSelectAllRecords(Grid: TwwDBGrid;
Selecting: Boolean; var Accept: Boolean);
begin
if (myList<>nil) and (not Selecting) then
mylist.clear;
end;
Then define mylist in your form as follows.
mylist: TList<TBookmark>
You may also want to add code in your form's destructor to free mylist using the code below.
mylist.free
Then when you want to iterate through the list in the user's order, you can use the following code. Note to add System.Generics.Collections to your form's uses clause.
var
enum: TEnumerator<TBookmark>;
current: TBookmark;
begin
with wwdbgrid1, wwdbgrid1.datasource.dataset do begin
DisableControls; { Disable controls to improve performance }
enum:= mylist.GetEnumerator;
for current in mylist do
begin
GotoBookmark(current);
showmessage(fieldbyname('code').asstring);
end;
enum.Free;
EnableControls;
end;
end
Comments
0 comments
Please sign in to leave a comment.