wxListCtrl multiple selection determination

From the docs and the demo, it appears that while there is a means of

finding out how many rows are selected (GetSelectedItemCount), there is no
GetSelectedItems() function for wxListCtrl to get the ones actually
selected.

I gather this means that I have to either keep state and manage an external
list of currently selected row indices as they get selected/deselected, or
walk the list items whenever I need to find out, correct? Is there
something
in the wxPython wrapper that makes this easier/does this for me that's
not in the wxWindows docs or the demo?

/Will Sadkin
Parlance Corporation
www.nameconnector.com

walk the list items whenever I need to find out,

This walks the list of items:

        selected=
        for i in range(0,self.GetItemCount()):
            if self.GetItemState(i, wxLIST_MASK_STATE)&wxLIST_STATE_SELECTED:
                selected.append(i)
or even:

  selected=[i for i in range(0,self.GetItemCount()) \
    if self.GetItemState(i, wxLIST_MASK_STATE)&wxLIST_STATE_SELECTED]

This isn't really onerous anyway since each piece of code will end up
doing something with each item that isn't the same as other code. For
example one of my pieces of code uses GetItemText on each item, other
pieces want GetItem.

Roger

Will Sadkin wrote:

From the docs and the demo, it appears that while there is a means of
finding out how many rows are selected (GetSelectedItemCount), there is no
GetSelectedItems() function for wxListCtrl to get the ones actually
selected.

I gather this means that I have to either keep state and manage an external list of currently selected row indices as they get selected/deselected, or walk the list items whenever I need to find out, correct? Is there
something in the wxPython wrapper that makes this easier/does this for me that's
not in the wxWindows docs or the demo?

  item = listctrl.GetFirstSelected()
  while item != -1:
    # do whatever
    item = listctrl.GetNextSelected(item)

ยทยทยท

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