Confusing ListCtrl behavior.

Try the following solution:

    def evt_selected(self, event):
        wx.CallAfter(self.selectIt, event.m_itemIndex)

    def selectIt(self, new_select):
        if self.cur_select is not None and new_select != self.cur_select:
            dlg = wx.MessageDialog(self,
                                   'Allow selection to change?',
                                   'Some Dialog',
                                   wx.YES|wx.NO|wx.CENTRE|wx.ICON_WARNING)

            answer = dlg.ShowModal()

            if answer == wx.ID_NO:
               self.list_ctrl_1.SetItemState(new_select,
                                             0,
                                             wx.LIST_STATE_FOCUSED|wx.LIST_STATE_SELECTED,
                                             )

               self.list_ctrl_1.SetItemState(self.cur_select,
                                             wx.LIST_STATE_FOCUSED|wx.LIST_STATE_SELECTED,
                                             wx.LIST_STATE_FOCUSED|wx.LIST_STATE_SELECTED,
                                             )
               return

        self.cur_select = new_select
        self.list_ctrl_1.Focus(new_select)

Rudolf Gärtner wrote:

Try the following solution:

...

That acts weird in a different way . The re-selection never occurs, leaving nothing selected if you chose to not let the selection change (but the focus marker is set properly). It's better than the other way (users are only bothered once - and the incorrect list item is not shown selected), and since I've customized all the controls anyway *, adding an on-focus handler to each control to make sure the proper list item is selected would finish the the work-around.

* so this works in every situation:
row = ...('SELECT * FROM table WHERE ...')
for column in row:
    self.control[column].SetValue(row[column])

and

def control_changed(self, event):
    obj = event.GetEventObject()
    row[obj.column] = obj.GetValue()

listctrl-2.py (1.85 KB)