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
WxDataViewListCtrl not sorting by column
- ColleenKobe
- Earned some good credits
- Posts: 109
- Joined: Mon Aug 31, 2015 3:47 pm
Re: WxDataViewListCtrl not sorting by column
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?
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?
Re: WxDataViewListCtrl not sorting by column
doesnt that make the most sense?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?
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.
Re: WxDataViewListCtrl not sorting by column
After adding your items in wxDataViewCtrl call the following:
Code: Select all
wxDataViewCtrl::GetModel()->Resort();