selecting an item in a wxListCtrl

What is the correct way to programmatically trigger the selection of an
item in a wxListCtrl? I want the wxListCtrl to behave as if the user had
actually selected the item (using the mouse, for example).

···

--
/Jesper

Jesper Eskilson wrote:

What is the correct way to programmatically trigger the selection of an
item in a wxListCtrl? I want the wxListCtrl to behave as if the user had
actually selected the item (using the mouse, for example).

     def Select(self, idx, on=1):
         '''[de]select an item'''
         if on: state = wxLIST_STATE_SELECTED
         else: state = 0
         self.SetItemState(idx, state, wxLIST_STATE_SELECTED)

It should be focused too:

     def Focus(self, idx):
         '''Focus and show the given item'''
         self.SetItemState(idx, wxLIST_STATE_FOCUSED,
                                wxLIST_STATE_FOCUSED)
         self.EnsureVisible(idx)

···

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