I have a wx.ListCtrl which I would like to disable so that entire control is grayed out and clicking on its items won’t do anything. It seems that a call to lc.Enable(False) doesn’t have the effect. Am I doing something wrong here, or is this not a feature of the ListCtrl? If it’s not a feature, is there a way to mimic it, or another type of list control that can be disabled?
Below is an example. In the example I’m using a virtual control, but I also tried with a non-virtual control and that didn’t disable either.
Thanks, Tom
import wx
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title="Test", size=(300, 300))
self.panel = wx.Panel(self, -1)
btn = wx.Button(self.panel, -1, "btn", pos=(10,10))
lc = LC(self.panel)
self.panel.Enable(False)
btn.Enable(False)
lc.Enable(False)
class LC(wx.ListCtrl):
def __init__(self, parent):
self.item_list = ["A", "B", "C"]
wx.ListCtrl.__init__(self, parent, -1, pos=(10, 50), size=(200,200),
style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_NO_HEADER|wx.LC_SINGLE_SEL|wx.BORDER_NONE)
self.InsertColumn(0, "groups")
self.SetItemCount(len(self.item_list))
self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._Ping)
def OnGetItemText(self, item, col):
if col==0:
return self.item_list[item]
def OnGetItemImage(self, item):
return -1
def OnGetItemAttr(self, item):
return None
def _Ping(self, evt):
x = evt.GetItem().GetText()
print "ping", x
if name==“main”:
app = wx.App()
frame = TestFrame()
frame.Show(True)
frame.Layout()
app.MainLoop()