[wxPython] Selecting wxListCtrl items programmatically

Hi wxPythonistas,

Neither:

    def EnsurePreviewVisible(self, pg = 0):
        maxpg = self.currPreview.pages
        for i in range(maxpg):
            if i == pg:
                self.faxPreview.SetItemState(i, wxLIST_STATE_SELECTED,
                                   wxLIST_MASK_STATE)
            else:
                self.faxPreview.SetItemState(i, 0, wxLIST_MASK_STATE)
        self.faxPreview.EnsureVisible(pg)

nor:

    def EnsurePreviewVisible(self, pg = 0):
        maxpg = self.currPreview.pages
        for i in range(maxpg):
            li = self.faxPreview.GetItem(i)
            if i == pg:
    li.m_state |= wxLIST_STATE_SELECTED
            else:
    li.m_state &= ~wxLIST_STATE_SELECTED
            self.faxPreview.SetItem(li)
        self.faxPreview.EnsureVisible(pg)

work! Why?

Cheers,
  Hans-Peter

wxListCtrl has this helper method added to it by the wrappers:

    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)

···

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

That did it.

Thanks a lot,
  Hans-Peter

···

On Monday, 4. March 2002 19:37, Robin Dunn wrote:

wxListCtrl has this helper method added to it by the wrappers:

    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)