wxListCtrl sorting order in MSW

70 views
Skip to first unread message

Martín Sebastián Wain

unread,
Nov 24, 2009, 9:45:24 AM11/24/09
to wx-u...@googlegroups.com
Hello, I've read the wxListCtrl sample and all, but I can't figure this out.

First of all, it's weird that by default wxListCtrl in MSW doesn't sort on Column Click as it does in OS X.

That said, I can't figure out a way to make it work even with my custom sorting.
How can I know before sorting the column ordering (ascending/descending) to
-at least- pass it as a parameter to the sort function?

I do sorting like this:

void PropertiesFrame::OnListColClick(wxListEvent &evt)
{
    switch(evt.GetColumn()) {
        case 0:
            lstSpriteTypes_->SortItems(sort_spriteTypes_name, NULL);
        case 1:
            lstSpriteTypes_->SortItems(sort_spriteTypes_deco, NULL);
        case 2:
            lstSpriteTypes_->SortItems(sort_spriteTypes_file, NULL);
    }
    evt.Skip();
}

And it sorts ok, but I want to be able to change between ascending and descending
as every other app ever does (default Windows behaviour)

I'm using svn-r60362 on MSW and 2.9.0 in Mac.

Thanks for your time
Regards

--
-Martín
Two bananas and milk [ http://www.tbam.com.ar ]

Vadim Zeitlin

unread,
Nov 24, 2009, 10:34:34 AM11/24/09
to wx-u...@googlegroups.com
On Tue, 24 Nov 2009 11:45:24 -0300 Martín Sebastián Wain <nitra...@gmail.com> wrote:

MSW> First of all, it's weird that by default wxListCtrl in MSW doesn't sort on
MSW> Column Click as it does in OS X.

AFAIR it's a bug that OS X version does sorting automatically because, in
fact, sorting by the clicked column might not always make sense.

MSW> That said, I can't figure out a way to make it work even with my custom
MSW> sorting.
MSW> How can I know before sorting the column ordering (ascending/descending) to
MSW> -at least- pass it as a parameter to the sort function?

You need to store it as a variable in your code, as simple as this.

MSW> And it sorts ok, but I want to be able to change between ascending and
MSW> descending as every other app ever does (default Windows behaviour)

It's not default in the sense that it's implemented in each of these apps,
the native listview control doesn't do anything at all when you click on
its header.

Admittedly, it would be nice to encapsulate this in wx but it's not
difficult to do it on your own and it would, on the contrary, be very
difficult to do it in wxListCtrl itself because it has no idea about the
data it contains. wxDataViewCtrl, with its clear separation of the model
from the control itself, has an advantage here and can do it.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Martín Sebastián Wain

unread,
Nov 24, 2009, 11:06:37 AM11/24/09
to wx-u...@googlegroups.com
Thanks for your quick answer!

I was just asking to know (because I must keep the last column pressed,
and the ordering of each, and it's a drag... perhaps it was already implemented :)

I definetly think that wxListCtrl is a cause of problems, its confusing to say the least.
Luckily the wxWiki became great help!

One of this days I'll create a templated proxy-decorator class for wxListCtrl
and wxTreeView. (Because I use wxFormBuilder for good IDE creation,
and custom-controls are not visualized)

Thanks again!
-Martín
Reply all
Reply to author
Forward
0 new messages