How to select all items of virtual wxListCtrl

346 views
Skip to first unread message

Edmund

unread,
Mar 29, 2012, 5:26:22 AM3/29/12
to wx-u...@googlegroups.com
Hi,
 
I am using wxListCtrl to display thousands of items with virutal and report style. One problem that I encountered is that there seems no function enable me to select all items (rows). I attempted to call wxListCtrl::SetItemState(long item, long state, long stateMask) for all items. But it runs very slow. Do you have any better ideas?
 
for(int j=0;j<GetItemCount();++j)
   SetItemState(j,wxLIST_STATE_SELECTED,wxLIST_STATE_SELECTED);
 
Regards
Edmund
 

Vadim Zeitlin

unread,
Mar 29, 2012, 7:41:40 AM3/29/12
to wx-u...@googlegroups.com
On Thu, 29 Mar 2012 02:26:22 -0700 (PDT) Edmund wrote:

E> I am using wxListCtrl to display thousands of items with virutal and report
E> style. One problem that I encountered is that there seems no function
E> enable me to select all items (rows).

No. And while it could be added easily to the generic wxListCtrl (which
uses wxSelectionStore internally which does have SelectRange() method), I'm
not sure about how this could be implemented for the native MSW version.

E> Do you have any better ideas?

First, try using wxWindowUpdateLocker around your code. Second, if you can
find a way to do it with the native MSW control, don't hesitate to submit a
patch doing this for inclusion in wx, it would be welcome.

Good luck,
VZ

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

Edmund

unread,
Mar 29, 2012, 10:35:23 PM3/29/12
to wx-u...@googlegroups.com

Thank you Vadim.

wxWindowUpdateLocker doesn't help. To bypass this issue I am trying to mange selected items myself. I have a std:unordered_set<long> m_selects variable to store all items which are in selected state. Then I bind mouse events to member functions of the derived class from wxListView.
 
In the mouse event handling functions, the selected items will be inserted into m_selects, while deselected will be removed from m_selects. RefreshItem() is called to refresh state changed items.
 
I override OnGetItemAttr function to set item state. However, it looks I can only set text and background color to reflect select/deselected state, but I am not able to simulate item with focus which should have a dotted line around.
 
Regards
Edmund

Vadim Zeitlin

unread,
Mar 30, 2012, 4:09:42 AM3/30/12
to wx-u...@googlegroups.com
On Thu, 29 Mar 2012 19:35:23 -0700 (PDT) Edmund wrote:

E> To bypass this issue I am trying to mange selected items myself.

I think it would be much simpler to modify wxListCtrl itself to support
this functionality.

BTW, I realized that I do know how to select all items in a virtual list
control under MSW: we need to store the selected state ourselves (using the
already mentioned wxSelectionStore) which means sending LVM_SETCALLBACKMASK
to the control and then returning the correct state from LVN_GETDISPINFO
handler. This looks relatively simple to do so, once again, I'd encourage
you to try to add SelectRange() and SelectAll() methods to wxListCtrl
itself. It would be definitely simpler than doing it outside of it and the
only extra thing you need to do to get it accepted in wxWidgets is to add a
documentation for the new methods to interface/wx/listctrl.h (which will
probably be just a few lines for these two).

Edmund

unread,
Mar 30, 2012, 7:07:07 AM3/30/12
to wx-u...@googlegroups.com

Thanks for the indication!

I have implmented the solution which I previously mentioned and it looks work well. Actually I have two windows, one is a wxScrolledWindow one which pictures are drawn and another one is a list control. The first one does centainly needs manual control of select/deselect/focus/select all/... Now I prefer the two have the same mechanims not only because the list control has some difficulties to select all.
 
The method you mentioned I will try later. But now I am happy with what I have done. Thanks again!
 
Regards
Edmund
Reply all
Reply to author
Forward
0 new messages