# Virtual ListCtrl not sortable by clicking the header?

**URL:** <https://www.ruby-forum.com/t/virtual-listctrl-not-sortable-by-clicking-the-header/177868>\
**Category:** wxRuby\
**Created:** [October 26, 2009, 12:14am UTC](https://www.ruby-forum.com/t/virtual-listctrl-not-sortable-by-clicking-the-header/177868 "2009-10-26T00:14:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixellover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pixellover](https://www.ruby-forum.com/u/pixellover)\
**Post date:** [October 26, 2009, 12:14am UTC](https://www.ruby-forum.com/t/virtual-listctrl-not-sortable-by-clicking-the-header/177868/1 "2009-10-26T00:14:51Z")

</div>

I just realised, that as soon as I add Wx::LC\_VIRTUAL to the style,  
the list stops being sortable by clicking on the header. Are virtual  
lists always unsortable by clicking on the header?

Regards,  
Timo

---

<div class="post-metadata">

**Author:** ![pixellover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pixellover](https://www.ruby-forum.com/u/pixellover)\
**Post date:** [October 27, 2009, 3:00pm UTC](https://www.ruby-forum.com/t/virtual-listctrl-not-sortable-by-clicking-the-header/177868/2 "2009-10-27T15:00:41Z")

</div>

Timo S. wrote:

> I just realised, that as soon as I add Wx::LC\_VIRTUAL to the style,  
> the list stops being sortable by clicking on the header. Are virtual  
> lists always unsortable by clicking on the header?

No, they are not unsortable, but you have to do the work yourself. In a  
“normal” ListCtrl, the control has knowledge of all the contents, so can  
help you. In a virtual ListCtrl, it doesn’t know all the contents as you  
supply them on demand.

You need to handle the events for the clicking of the column headers  
yourself (_evt\_list\_col\_click etc)_, and then re-order the contents  
(data to be supplied by the virtual functions). So if you were using a  
SQL call to populate the underlying data, you might add an ORDER BY  
clause.

This for wxPython, but might be helpful:

[http://code.activestate.com/recipes/426407/](http://code.activestate.com/recipes/426407/)  
[http://archives.devshed.com/forums/python-122/sorting-wxlistctrl-with-lc-virtual-2218172.html](http://archives.devshed.com/forums/python-122/sorting-wxlistctrl-with-lc-virtual-2218172.html)

alex

---

<div class="post-metadata">

**Author:** ![pixellover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pixellover](https://www.ruby-forum.com/u/pixellover)\
**Post date:** [October 27, 2009, 3:16pm UTC](https://www.ruby-forum.com/t/virtual-listctrl-not-sortable-by-clicking-the-header/177868/3 "2009-10-27T15:16:30Z")

</div>

Hi Alex,

hey, that’s sound promising. Thanks for pointing me into the right  
direction. I’ll take a deeper look into it. I think it would be  
usefull if this would be part of the documentation?

Regards,  
Timo

Am 27.10.2009 um 15:00 schrieb Alex F.:
