Layout questions with ListCtrl

Michael Eager <[email protected]> Tue, 8 Dec 2020 11:07:20 -0800
Newsgroups gmane.comp.python.wxpython
Message-ID <[email protected]>
I'm trying to use a ListCtrl in a SplitterWindow and I've been having 
trouble getting it to format correctly.  It turns out this isn't 
confusion caused by the SplitterWindow, but my lack of understanding of 
layout in ListCtrl.

I created a simple app (attached) which creates a wx.Frame containing a 
wx.Panel which has a StaticText and wx.ListCtrl.  I've tried setting the 
column width at two different times (after the ListCtrl is created and 
after it is filled with data) and two different ways (with fixed size 
and AUTOSIZE).

The only one which works is setting AUTOSIZE after filling in data. 
Setting fixed column widths doesn't work either time.  (testopt = 1)

I've tried inserting calls to Layout() at various locations, but that 
doesn't seem to affect anything.

Can someone explain?


-- 
Michael Eager

-- 
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wxpython-users/8e00535b-8c55-3ede-f708-c9b24ec0ce29%40eagercon.com.
try.py (text/x-python, 1.7 KB)
import wx

testopt = 3

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1, "Panel", size=(500,500))

        panel2 = Panel2(self)
        panel2.update()

class Panel2(wx.Panel):

    def __init__(self, parent):
        super().__init__(parent)

        box = wx.BoxSizer(wx.VERTICAL)
        p = wx.StaticText(self, -1, "Right Panel")
        box.Add(p, 0, wx.ALIGN_CENTER)

        self.list = wx.ListCtrl(self, -1, style = wx.LC_REPORT)
        box.Add(self.list, 1, wx.ALL|wx.EXPAND)
        self.list.InsertColumn(0, "Col 1")
        self.list.InsertColumn(1, "Col 2", wx.LIST_FORMAT_RIGHT)
        self.list.InsertColumn(2, "Col 3", wx.LIST_FORMAT_RIGHT)

        if testopt == 3:
            self.list.SetColumnWidth(0, 20)
            self.list.SetColumnWidth(1, 10)
            self.list.SetColumnWidth(2, 20)
        elif testopt == 4:
            self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
            self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
            self.list.SetColumnWidth(2, wx.LIST_AUTOSIZE)

        self.SetSizer(box)

    def update(self):
        index = 0
        for n in range(10):
            self.list.InsertItem (index, "col 1 text")
            self.list.SetItem(index, 1, 'col 2 - ' + str(index))
            self.list.SetItem(index, 2, '12345')
            index += 1

        if testopt == 1:
            self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE)
            self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE)
            self.list.SetColumnWidth(2, wx.LIST_AUTOSIZE)
        elif testopt == 2:
            self.list.SetColumnWidth(0, 20)
            self.list.SetColumnWidth(1, 10)
            self.list.SetColumnWidth(2, 20)


app = wx.App(0)
frame = MyFrame(None)
frame.Show()
app.MainLoop()