UltimateListCtrl sort problem

The sort feature of a UltimateListCtrl, does not work when SetItemData() is not called with a correct parameter (unique int) for each item.

For example :

  • When not calling SetItemData() at all, the sorting function is called with both item1 and item2 set to 0.
  • When calling SetItemData(item, 1) for each item, the sorting function is called with both item1 and item2 set to 1.

So, SetItemData() must be called with a unique int for each item in the list.

If this behavior is intended, it should be specified in the documentation.

Note : Using wxPython 4.1.0 (same behavior with 4.0.7post2)

Hmm… It looks like it may have originally been intended to sort by the actual items but then it was made to be compatible with wx.ListCtrl instead. This is from the wx.ListCtrl documentation:

The parameter item1 is the client data associated with the first item (NOT the index). The parameter item2 is the client data associated with the second item (NOT the index). The parameter data is the value passed to SortItems itself.

Notice that the control may only be sorted on client data associated with the items, so you must use SetItemData if you want to be able to sort the items in the control.

See also:

This makes sense.

I never realized it for wx.ListCtrl since I always use SetItemData() which passed value is the index of a list containing python objects associated with the ListCtrl.
With UltimateListCtrl my intent was to use SetItemPyData() which would have allow me to get rid of the list and SetItemData().
But because sorting needs SetItemData() to be called, SetItemPyData() has no more interest (in this case).
Anyway, that’s not a problem since it is clearly specified in UltimateListCtrl documentation.

Thanks for clarifying.