CGDevTools Forum

Welcome to the Official CGDevTools Support Community Forums.

Sorting items

by GerritS » 26 Nov 2018 17:29

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.
GerritS
 
Posts: 19
Joined: 29 May 2017 20:16

by Alexander Bulei » 29 Nov 2018 10:12

Hi GerritS,

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

Best Regards.
Group: Developers | Support Team

  • info [at] cgdevtools.com - General information
  • sales [at] cgdevtools.com - Sales department
  • support [at] cgdevtools.com - Product and Technical Support
User avatar
Alexander Bulei
Site Admin
 
Posts: 3635
Joined: 15 May 2012 08:52
Location: Mealhada, Portugal

by GerritS » 03 Dec 2018 14:40

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.
GerritS
 
Posts: 19
Joined: 29 May 2017 20:16


Return to JQCheckBoxList

cron

Who is online

Users browsing this forum: No registered users and 1 guest

Contact Us.