[wxPython] get selection of a wxListCtrl

Is it possible to get the selected items of a wxListCtrl? There is no GetSelection() method within wxListCtrl.

I tried to use EVT_LIST_ITEM_SELECTED and EVT_LIST_ITEM_DESELECTED but it's so clumsy...

I don't need to know when an item is selected/deselected, I just need the selection at a certain moment.

Thanks,

Cristina.

···

-------------------------------------------------------
Xnet scaneaza automat toate mesajele impotriva virusilor folosind RAV AntiVirus.
Xnet automatically scans all messages for viruses using RAV AntiVirus.

Nota: RAV AntiVirus poate sa nu detecteze toti virusii noi sau toate variantele lor. Va rugam sa luati in considerare ca exista un risc de fiecare data cand deschideti fisiere atasate si ca MobiFon nu este responsabila pentru nici un prejudiciu cauzat de virusi.
Disclaimer: RAV AntiVirus may not be able to detect all new viruses and variants. Please be aware that there is a risk involved whenever opening e-mail attachments to your computer and that MobiFon is not responsible for any damages caused by viruses.

Is it possible to get the selected items of a wxListCtrl? There is no
GetSelection() method within wxListCtrl.

I tried to use EVT_LIST_ITEM_SELECTED and EVT_LIST_ITEM_DESELECTED but it's
so clumsy...

I don't need to know when an item is selected/deselected, I just need the
selection at a certain moment.

Thanks,

Cristina.

Take a look at wxListCtrl::GetNextItem

Ciao,
Alberto

Also might want to take a look at section 1.3 of the ListAndTreeControls section of the Wiki. I've just fixed the recipe with a piece of working code from a live project, so it should be a little less confusing :slight_smile: .

Strangely, I've found that, when using list controls, it's more robust to track the selection set from SELECT/DESELECT events than to do the index-based search described in the wiki, but then I made that observation almost 10 months ago, so things may have changed since then :slight_smile: .

Enjoy,
Mike

Alberto Griggio wrote:

···

Is it possible to get the selected items of a wxListCtrl? There is no GetSelection() method within wxListCtrl.

I tried to use EVT_LIST_ITEM_SELECTED and EVT_LIST_ITEM_DESELECTED but it's so clumsy...

I don't need to know when an item is selected/deselected, I just need the selection at a certain moment.

Thanks,

Cristina.

Take a look at wxListCtrl::GetNextItem

Ciao,
Alberto

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
_______________________________________
   Mike C. Fletcher
   Designer, VR Plumber, Coder
   http://members.rogers.com/mcfletch/

C. Iacob wrote:

Is it possible to get the selected items of a wxListCtrl? There is no GetSelection() method within wxListCtrl.

I tried to use EVT_LIST_ITEM_SELECTED and EVT_LIST_ITEM_DESELECTED but it's so clumsy...

I don't need to know when an item is selected/deselected, I just need the selection at a certain moment.

These methods should help:

     def GetFirstSelected(self, item):
         """return first selected item, or -1 when none"""
         return self.GetNextSelected(-1)

     def GetNextSelected(self, item):
         """return subsequent selected items, or -1 when no more"""
         return self.GetNextItem(item, wxLIST_NEXT_ALL,
                                 wxLIST_STATE_SELECTED)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!