Page 1 of 1

Sorting items

PostPosted: 26 Nov 2018 17:29
by GerritS
Hi, I add about 100 items (caption and value both set) to a JQCheckBoxList. After loading the list items I would like to sort them by (for example) the caption of the items.

I cannot get the sorting to work. I understand I should use a compare function and it can't be hard... however it's too hard for me. Can anyone give a small example to make my life easier ? Thanks.

Re: Sorting items

PostPosted: 29 Nov 2018 10:12
by Alexander Bulei
Hi GerritS,

Your question is related to the delphi programming...please use the google :)

Best Regards.

Re: Sorting items

PostPosted: 03 Dec 2018 14:40
by GerritS
Hi Alexander,

Sure thing I used Google quite extensively before posting my question ;-) After muddling through I managed to create a workable solution which I will post for anyone whos is in need of such. (elsewhere on the forum someone had the same sorting problems regarding a different component)

In the form declarations above the private part of the form declaration I added the declaration of my comparison function :

Code: Select all
function Comparison(Left, Right : TCollectionItem; var Data) : integer;
  private


This function itself is quite simple and sorts my items by the caption of the items :

Code: Select all
function TTestForm.Comparison(Left, Right : TCollectionItem; var Data) : integer;
begin
  Result := comparestr(TIWCGJQCheckBoxItem(Left).Caption,TIWCGJQCheckBoxItem(Right).Caption);
end;


And when I want to sort the list of items of my CheckBoxList I just use the following line :

Code: Select all
TestCheckBoxList.Items.SortItems(Comparison);


Best regards.