Sign in Join

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

Mailing lists / lazarus / 2015-04

Strange Alphasort in ListView

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

Valdas Jankūnas

Hello,

when I execute ListView.AlphaSort then ListView always sorts first column with default sort order. Also it resets SortColumn property to zero and SortOrder to default (see attached screenshot: before and after execution of Alphasort).

Why it not sorts current SortColumn with current SortOrder? Is this a Bug?

Tried in Qt, Gtk2 and Win widgetsets - same strange result.

Valdas Jank?nas -------------- next part -------------- A non-text attachment was scrubbed... Name: listview.png Type: image/png Size: 71076 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150414/1ce5bda8/attachment-0001.png>

Reply by email

Vojtěch Čihák
to Valdas Jankūnas

No, it isn't a bug.
?
In sources, you can see comment:
?
function AlphaSort: Boolean; // always sorts column 0 in sdAscending order ?
So if you want other sorting, you must set three sort-related properties: ?
ListView1.SortColumn:=1;
ListView1.SortDirection:=sdAscending;
ListView1.SortType:=stText;
?
It works, I just tested in Qt.
?
V.

Reply by email

Valdas Jankūnas
to Vojtěch Čihák

2015.04.14 15:34, Vojt?ch ?ih?k ra??:

Show quoted text 5 lines
No, it isn't a bug. In sources, you can see comment: function AlphaSort: Boolean; // always sorts column 0 in sdAscending order

Looked not in *primary* source (Google, Documentation) :)

Show quoted text 8 lines
So if you want other sorting, you must set three sort-related properties: ListView1.SortColumn:=1; ListView1.SortDirection:=sdAscending; ListView1.SortType:=stText; It works, I just tested in Qt.

Why I came to AlphaSort: in my source ListView is cleared (columns stays same) and populated with new info. After that current column (say SortColumn=1) is no sorted (Autosort is TRUE; tried in Qt, Gtk2 and Win) so I must somehow to trigger sorting. But how?

Valdas Jank?nas

Reply by email

Graeme Geldenhuys
to Valdas Jankūnas
Valdas Jank?nas wrote 5 lines
> > In sources, you can see comment: > > > > function AlphaSort: Boolean; // always sorts column 0 in sdAscending order Looked not in *primary* source (Google, Documentation) :)

Indeed, the documentation is a bit sparse. ;-)

http://lazarus-ccr.sourceforge.net/docs/lcl/comctrls/tcustomlistview.alphasort.html

ps:
How often is the online documentation regenerated and updated on the website?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Vojtěch Čihák
to Valdas Jankūnas: 2015.04.14 15:34, Vojt?ch ?ih?k ra??: Looked not in *primary* source (Google,…

I understand. Method Sort; is protected (as it is in Delphi). ?
You have probably no other choice than do
?
?ListView1.SortDirection:=sdDescending;
?ListView1.SortDirection:=sdAscending;
?
which works but it is unefficient, sorting is done twice. ?
I tried:
?ListView1.BeginUpdate;
?ListView1.SortDirection:=sdDescending;
?ListView1.EndUpdate;
?ListView1.SortDirection:=sdAscending;but it doesn't help, sorting is still done twice (at least on Qt).ListView has some flags to avoid sorting but those flags are private.V.? ?

Reply by email

Vojtěch Čihák
to Vojtěch Čihák

Delphi has no properties AutoSort, SortColumn and SortDirection nor methods BeginUpdate and EndUpdate. ?
I would provide a patch which will set Flag?lffPreparingSorting on BeginUpdate and reset it on EndUpdate. +one additional call of Sort on EndUpdate (maybe only if AutoSort is True) OR move Sort; form protected to public. ?
What is preferred?
?
V.

Reply by email

Valdas Jankūnas
to Vojtěch Čihák: I understand. Method Sort; is protected (as it is in Delphi). ? You have probably no…

2015.04.14 16:22, Vojt?ch ?ih?k ra??:

Show quoted text 17 lines
I understand. Method Sort; is protected (as it is in Delphi). You have probably no other choice than do ListView1.SortDirection:=sdDescending; ListView1.SortDirection:=sdAscending; which works but it is unefficient, sorting is done twice. I tried: ListView1.BeginUpdate; ListView1.SortDirection:=sdDescending; ListView1.EndUpdate; ListView1.SortDirection:=sdAscending;but it doesn't help, sorting is still done twice (at least on Qt).ListView has some flags to avoid sorting but those flags are private.V.

Thanks for mentioning protected Sort procedure. So I come to "dirty" solution:

- create helper class:

type
   THack = class(TListView)
   public
      procedure Trigger_sort;
   end;
  - implement "Trigger_sort":
procedure THack.Trigger_sort;
begin
     Sort;
end;
  - now when to trigger sort with current settings is needed then execute:
THack(ListView1).Trigger_sort;
  Works for me (at least in Qt (Linux) and Win (Windows7)).
Valdas Jank?nas

Reply by email

Valdas Jankūnas
to Vojtěch Čihák: Delphi has no properties AutoSort, SortColumn and SortDirection nor methods BeginUpdate…

2015.04.14 17:49, Vojt?ch ?ih?k ra??:

Show quoted text 11 lines
Delphi has no properties AutoSort, SortColumn and SortDirection nor methods BeginUpdate and EndUpdate. I would provide a patch which will set Flag lffPreparingSorting on BeginUpdate and reset it on EndUpdate. +one additional call of Sort on EndUpdate (maybe only if AutoSort is True) OR move Sort; form protected to public. What is preferred? V.

Solution to move "Sort" to "public" is more convenient for me if it not will break something (or will break?).

Valdas Jank?nas

Reply by email