Hello,
In one of my windows, I'm trying to move from a wx.ListBox to a
wx.ListCtrl. I want to have a vertical scroll bar but not a
horizontal scroll bar. All of the sizing works fine with the ListBox,
but with the ListCtrl, the minimum width appears to be too small and
there is an undesired horizontal scroll bar.
Any suggestions why moving from a ListBox to a ListCtrl would cause
this? Code excerpts are included below that show the working ListBox
and the broken ListCtrl.
Jeff
====== ListBox=============
class BallotsPanel(wx.Panel):
def __init__(self, parent, BFE):
wx.Panel.__init__(self, parent, -1)
...
self.ballotC = wx.ListBox(self, -1, choices=candidateList)
...
# Sizers
sizer = wx.BoxSizer(wx.HORIZONTAL)
leftSizer = wx.BoxSizer(wx.VERTICAL)
...
rightSizer = wx.BoxSizer(wx.VERTICAL)
rightSizer.Add(self.ballotC, 1, wx.EXPAND|wx.ALL, 5)
...
sizer.Add(rightSizer, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)
====== ListCtrl=============
# Subclass ListCtrl to include autowidth mixin
class BallotCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
def __init__(self, parent, ID):
style = wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_HRULES|wx.LC_VRULES
wx.ListCtrl.__init__(self, parent, ID, style=style)
listmix.ListCtrlAutoWidthMixin.__init__(self)
# Panel that includes ListCtrl
class BallotsPanel(wx.Panel):
def __init__(self, parent, BFE):
wx.Panel.__init__(self, parent, -1)
...
self.ballotC = BallotCtrl(self, -1) ## This is subclass of wx.ListCtrl
self.ballotC.InsertColumn(0, "R", wx.LIST_FORMAT_RIGHT)
self.ballotC.InsertColumn(1, "Candidate")
for c, name in enumerate(self.BFE.b.names):
if c in self.BFE.b.raw[self.BFE.i]:
r = self.BFE.b.raw[self.BFE.i].index(c)
self.ballotC.InsertStringItem(c, str(r+1))
else:
self.ballotC.InsertStringItem(c, "")
self.ballotC.SetStringItem(c, 1, name)
self.ballotC.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
self.ballotC.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)
...
# Sizers
sizer = wx.BoxSizer(wx.HORIZONTAL)
leftSizer = wx.BoxSizer(wx.VERTICAL)
...
rightSizer = wx.BoxSizer(wx.HORIZONTAL)
rightSizer.Add(self.ballotC, 1, wx.EXPAND|wx.ALL, 5)
sizer.Add(leftSizer, 2, wx.EXPAND|wx.ALL, 5)
sizer.Add(rightSizer, 1, wx.EXPAND|wx.ALL, 5)
self.SetSizer(sizer)
sizer.Fit(self)