wxpython - Expand list control vertically not horizontally
Question
I have a ListCtrl that displays a list of items for the user to select. This works fine except that when the ctrl is not large enough to show all the items, I want it to expand downwards with a vertical scoll bar rather than using a horizontal scroll bar as it expands to the right.
The ListCtrl's creation:
self.subjectList = wx.ListCtrl(self, self.ID_SUBJECT, style = wx.LC_LIST | wx.LC_SINGLE_SEL | wx.LC_VRULES)
Items are inserted using wx.ListItem:
item = wx.ListItem()
item.SetText(subject)
item.SetData(id)
item.SetWidth(200)
self.subjectList.InsertItem(item)
Solution
Use the wxLC_REPORT style.
import wx
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.test = wx.ListCtrl(self, style = wx.LC_REPORT | wx.LC_NO_HEADER)
for i in range(5):
self.test.InsertColumn(i, 'Col %d' % (i + 1))
self.test.SetColumnWidth(i, 200)
for i in range(0, 100, 5):
index = self.test.InsertStringItem(self.test.GetItemCount(), "")
for j in range(5):
self.test.SetStringItem(index, j, str(i+j)*30)
self.Show()
app = wx.PySimpleApp()
app.TopWindow = Test()
app.MainLoop()
OTHER TIPS
Try this:
import wx
class Test(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
self.test = wx.ListCtrl(self, style = wx.LC_ICON | wx.LC_AUTOARRANGE)
for i in range(100):
self.test.InsertStringItem(self.test.GetItemCount(), str(i))
self.Show()
app = wx.PySimpleApp()
app.TopWindow = Test()
app.MainLoop()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow