WxDataViewListCtrl not sorting by column

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
HansR
Earned a small fee
Earned a small fee
Posts: 14
Joined: Wed Apr 14, 2010 4:41 am
Contact:

WxDataViewListCtrl not sorting by column

Post by HansR » Thu May 06, 2010 5:38 am

I'm using a wxDataViewListCtrl with all columns marked as reorderable, and one marked as sortable. While the little sorted arrow appears in the column title when clicked, it doesn't sort the items. This is under Windows; I haven't tried on any other platform. At first I thought that it was because I hadn't provided a Compare() method for the data model, but the Compare() method is never called. Plus, the column in question is of type "double", which the default Compare() method handles nicely.

This looks like a bug to me, but before I submit a bug report, is there anything in particular that you need to do to get sorting working? Sorting works in the dataview demo, but that's with the tree model, not a list model.

Hans

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch » Wed Oct 13, 2010 12:06 am

I'm having this same problem.

Sorting by columns with strings and dates doesn't seem to work. =(

User avatar
ColleenKobe
Experienced Solver
Experienced Solver
Posts: 88
Joined: Mon Aug 31, 2015 3:47 pm

Re: WxDataViewListCtrl not sorting by column

Post by ColleenKobe » Fri Jul 14, 2017 2:11 pm

Did anyone get the wxDataViewListCtrl sorting to work? I'm having that issue now.

Sorting a wxDataViewListCtrl column is not mentioned in C:\wxWidgets\samples\dataview\dataview.cpp.

Is sorting supposed to be automatic? Or is it up to us to simply catch the OnDvlistctrl11DataviewColumnHeaderClick event, and then start our own handwritten sorting routine and redraw the wxDataViewListCtrl ourselves?

coderrc
Earned some good credits
Earned some good credits
Posts: 141
Joined: Tue Nov 01, 2016 2:46 pm

Re: WxDataViewListCtrl not sorting by column

Post by coderrc » Fri Jul 14, 2017 4:07 pm

ColleenKobe wrote:is it up to us to simply catch the OnDvlistctrl11DataviewColumnHeaderClick event, and then start our own handwritten sorting routine and redraw the wxDataViewListCtrl ourselves?
doesnt that make the most sense?

Imagine you were displaying database records. Your program would fetch X of Y records to display, because it would be dumb to load every DB record. If the user changes the sorting order or column, the expectation is that ALL records will be sorted not just the 30 that are currently displayed. So lets pretend X is 30 and Y is 20 000 and the current sort is "most recent first". When the user changes the sort to "oldest first" they expect to see the oldest of the 20 000 records first, not the oldest of the newest 30 records first.

That requires that the database be queried, results parsed, and the view repopulated. It seems like a crazy stretch of the imagination to think that a generic view control would know how to do that.

Anil8753
Experienced Solver
Experienced Solver
Posts: 80
Joined: Sat Jan 16, 2016 5:57 am

Re: WxDataViewListCtrl not sorting by column

Post by Anil8753 » Wed Jul 19, 2017 3:37 am

After adding your items in wxDataViewCtrl call the following:

Code: Select all

wxDataViewCtrl::GetModel()->Resort();

Post Reply