2

我有一个 ListCtrl,它显示供用户选择的项目列表。这很好用,除了当 ctrl 不够大以显示所有项目时,我希望它使用垂直 scoll 条向下扩展,而不是在向右扩展时使用水平滚动条。

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

2 回答 2

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()
于 2008-10-18T16:18:05.537 回答
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()
于 2008-10-18T17:53:14.643 回答