In that case probably want to look at handling
EVT_LIST_ITEM_DESELECTED to ensure that a selection is made after that
is called. Not a 100% sure off the top of my head on the order in
which this is fired (i.e before or after the new selection event), so
may need to set a timer or issue a CallAfter to a function to check if
there is a selection after this has been handled.
The attached works fine for me.
Generally control methods shouldn't generate events, unfortunatly wx
is rather inconsistent in this regards.
Cody
import wxclass MyFrame(wx.Frame):
def __init__(self):
super(MyFrame, self).__init__(None)self.l = MyListCtrl(self)
self.l.Select(0)class MyListCtrl(wx.ListCtrl):
def __init__(self, parent):
super(MyListCtrl, self).__init__(parent, style=wx.LC_REPORT|wx.LC_SINGLE_SEL)self.InsertColumn(0, "Foo")
self.InsertColumn(1, "Bar")
for x in range(5):
self.Append(("Column 0", "Column 1"))self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnDeSel)
def OnDeSel(self, evt):
wx.CallAfter(self.DoForcedSel, evt.GetIndex())def DoForcedSel(self, sel):
if self.GetSelectedItemCount() == 0:
self.Select(sel)app = wx.App(False)
f = MyFrame()
f.Show()
app.MainLoop()