Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2013-07

Can't make working sorting inTListView

4 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Geoffray Levasseur-Brandin

Hello all !!

I've got a problem with the following code :

procedure TfMain.lvPackageListColumnClick(Sender: TObject; Column:
TListColumn);
begin
  if Column.Index = FLastSortedColumn then
    FAscending := not FAscending
  else
    FLastSortedColumn := Column.Index;
  lvPackageList.SortColumn := Column.Index;
end;
procedure TfMain.lvPackageListCompare(Sender: TObject; Item1, Item2:
TListItem;
  Data: Integer; var Compare: Integer);
begin
  case Data of
    0: Compare := AnsiCompareText(Item1.Caption, Item2.Caption); //pkgname
    1: Compare := CompareVersion(Item1.SubItems[0], Item2.SubItems[0]);
//installed version
    2: Compare := CompareVersion(Item1.SubItems[1], Item2.SubItems[1]); //last
version
    3: Compare := CompareInstSize(Item1.Caption, Item2.Caption); //installed
size
    4: Compare := CompareDefSize(Item1.Caption, Item2.Caption); //pkgsize
    5: Compare := AnsiCompareText(Item1.SubItems[4], Item2.SubItems[4]);
//description
  end;
  if not FAscending then
    Compare := -Compare;
end;

Whatever the column I'm clicking on it's always sorting the first column. I do really not understand what's wrong. All the functions I've made giving Compare its value returns correctly 1 if Itme1 > Item2, 0 if equal and -1 if Item1 < Item2.

Thanks for any help.

Geoffray ? Fatalerrors ? Levasseur-Brandin http://www.geoffray-levasseur.org/ http://0.tuxfamily.org/ GNU/PG key : BF8BB8407CD26E89466CDA9BB1030FC59EF87775 Errare humanum est sed perseverare diabolicum aut cretinum. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 490 bytes Desc: This is a digitally signed message part. URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130729/fb900202/attachment.bin>

Reply by email

Flávio Etrusco
to Geoffray Levasseur-Brandin
Geoffray Levasseur-Brandin wrote 38 lines
Hello all !! I've got a problem with the following code : procedure TfMain.lvPackageListColumnClick(Sender: TObject; Column: TListColumn); begin if Column.Index = FLastSortedColumn then FAscending := not FAscending else FLastSortedColumn := Column.Index; lvPackageList.SortColumn := Column.Index; end; procedure TfMain.lvPackageListCompare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer); begin case Data of 0: Compare := AnsiCompareText(Item1.Caption, Item2.Caption); //pkgname 1: Compare := CompareVersion(Item1.SubItems[0], Item2.SubItems[0]); //installed version 2: Compare := CompareVersion(Item1.SubItems[1], Item2.SubItems[1]); //last version 3: Compare := CompareInstSize(Item1.Caption, Item2.Caption); //installed size 4: Compare := CompareDefSize(Item1.Caption, Item2.Caption); //pkgsize 5: Compare := AnsiCompareText(Item1.SubItems[4], Item2.SubItems[4]); //description end; if not FAscending then Compare := -Compare; end; Whatever the column I'm clicking on it's always sorting the first column. I do really not understand what's wrong. All the functions I've made giving Compare its value returns correctly 1 if Itme1 > Item2, 0 if equal and -1 if Item1 < Item2.

I'm not really sure how TListView is supposed to work, however by debugging the code I can see 'Data' is always 0. Maybe you're supposed to just use ListView.SortColumn.

-Fl?vio

Show quoted text 15 lines
Thanks for any help. -- Geoffray ? Fatalerrors ? Levasseur-Brandin http://www.geoffray-levasseur.org/ http://0.tuxfamily.org/ GNU/PG key : BF8BB8407CD26E89466CDA9BB1030FC59EF87775 Errare humanum est sed perseverare diabolicum aut cretinum. -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Frederic Da Vitoria
to Flávio Etrusco

2013/7/29 Fl?vio Etrusco

Show quoted text 51 lines
On Mon, Jul 29, 2013 at 10:20 AM, Geoffray Levasseur-Brandin wrote: > Hello all !! > > I've got a problem with the following code : > > procedure TfMain.lvPackageListColumnClick(Sender: TObject; Column: > TListColumn); > begin > if Column.Index = FLastSortedColumn then > FAscending := not FAscending > else > FLastSortedColumn := Column.Index; > lvPackageList.SortColumn := Column.Index; > end; > > procedure TfMain.lvPackageListCompare(Sender: TObject; Item1, Item2: > TListItem; > Data: Integer; var Compare: Integer); > begin > case Data of > 0: Compare := AnsiCompareText(Item1.Caption, Item2.Caption); //pkgname > 1: Compare := CompareVersion(Item1.SubItems[0], Item2.SubItems[0]); > //installed version > 2: Compare := CompareVersion(Item1.SubItems[1], Item2.SubItems[1]); //last > version > 3: Compare := CompareInstSize(Item1.Caption, Item2.Caption); //installed > size > 4: Compare := CompareDefSize(Item1.Caption, Item2.Caption); //pkgsize > 5: Compare := AnsiCompareText(Item1.SubItems[4], Item2.SubItems[4]); > //description > end; > if not FAscending then > Compare := -Compare; > end; > > Whatever the column I'm clicking on it's always sorting the first column. I do > really not understand what's wrong. All the functions I've made giving Compare > its value returns correctly 1 if Itme1 > Item2, 0 if equal and -1 if Item1 < > Item2. I'm not really sure how TListView is supposed to work, however by debugging the code I can see 'Data' is always 0. Maybe you're supposed to just use ListView.SortColumn.

http://www.delphitips.net/2008/04/10/sort-listview-by-clicking-on-columns/and http://stackoverflow.com/questions/15605509/sorting-tlistview-columns-cont-ascending-descendingboth use directly the columns instead of the Data parameter. IIRC, that's how I did it the few times I used TListView. I don't know what Data is for, though.

Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130729/659cf470/attachment.html>

Reply by email

Geoffray Levasseur-Brandin
to Frederic Da Vitoria

Thank you very much ! I get it working well :D

Le lundi 29 juillet 2013 17:20:20 Frederic Da Vitoria a ?crit :

Show quoted text 12 lines
http://www.delphitips.net/2008/04/10/sort-listview-by-clicking-on-columns/an d http://stackoverflow.com/questions/15605509/sorting-tlistview-columns-cont-> ascending-descendingboth use directly the columns instead of the Data parameter. IIRC, that's how I did it the few times I used TListView. I don't know what Data is for, though. -- Frederic Da Vitoria (davitof) Membre de l'April - ? promouvoir et d?fendre le logiciel libre ? - http://www.april.org
Geoffray ? Fatalerrors ? Levasseur-Brandin http://www.geoffray-levasseur.org/ http://0.tuxfamily.org/ GNU/PG key : BF8BB8407CD26E89466CDA9BB1030FC59EF87775 Errare humanum est sed perseverare diabolicum aut cretinum. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 490 bytes Desc: This is a digitally signed message part. URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20130730/a4e1853e/attachment.bin>

Reply by email