2008-10-18 42 views
2

我有一個ListCtrl顯示用戶選擇的項目列表。這工作正常,除了當ctrl不足以顯示所有項目時,我希望它通過垂直滑動條向下擴展,而不是在向右擴展時使用水平滾動條。wxpython - 垂直擴展列表控件不水平

的的ListCtrl的創作:

self.subjectList = wx.ListCtrl(self, self.ID_SUBJECT, style = wx.LC_LIST | wx.LC_SINGLE_SEL | wx.LC_VRULES) 

項目使用wx.ListItem插入:

item = wx.ListItem() 
item.SetText(subject) 
item.SetData(id) 
item.SetWidth(200) 
self.subjectList.InsertItem(item) 

回答

3

使用wxLC_REPORT風格。

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() 
+0

usering代替wx.LC_LIST wx.LC_REPORT給了我一個垂直滾動條,但所有的文本項dissapear(雖然滾動條看上去只有一個大小合適的完整列表...) – 2008-10-18 16:27:20

+0

您必須在使用它們之前明確插入列。我加了一個例子 – 2008-10-18 22:08:35

1

試試這個:

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()