Newbie problem with wxListCtrl

Tom nospam at nospam.com
Sun Oct 15 10:28:51 EDT 2000


Frank,

You need to insert items, as well as setting the item's string.

So, before your line:
             self.lc.SetStringItem(i, 0, "%d" % i)
Add a line like this:
            self.lc.InsertStringItem(i, label);

Where label is a string that serves no purposes (doesn't get displayed) that
I've deteremined.  It's all the same on the Win32 api - this is a common
mistake.

Tom.


"Frank P. Miles" <fpmi at home.com> wrote in message
news:39E936E0.3BADC7D8 at home.com...
> Hello all --
>
> I'm trying to use wxPython for a database front-end project.  Perhaps I
> haven't
> stared at the source code enough, but the documentation hasn't been
> enough to get around
> the basic problem of using wxListCtrl.  Here's a simple bit of code:
>
> <start of code>
> #! /usr/bin/python
>
> from wxPython.wx import *
>
> class MyFrame(wxFrame):
>     def __init__(self, parent):
>         wxFrame.__init__(self, parent, -1, "test", size=(400, 200))
>         self.lc = wxListCtrl(self, -1, style =
> wxLC_REPORT|wxSUNKEN_BORDER)
>         self.lc.InsertColumn(0, "Column 0 Long enough")
>         self.lc.InsertColumn(1, "B-Column Real long")
>         for i in range(10):
>             self.lc.SetStringItem(i, 0, "%d" % i)
>             self.lc.SetStringItem(i, 1, "boogers all!")
>         self.lc.SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER)
>         self.lc.SetColumnWidth(1, wxLIST_AUTOSIZE_USEHEADER)
>
> class MyApp(wxApp):
>     def OnInit(self):
>         frame = MyFrame(NULL)
>         frame.Show(true)
>         self.SetTopWindow(frame)
>         return true
>
> app = MyApp(0)
> app.MainLoop()
>
> <\end of code>
>
> No data are printed, nor are the column headings of sufficient length.
> I've tried this both under Linux and Win98, with the same result, so
> it would seem that it's my code, not a system configuration problem.
> The wxPython demo works fine in both.  I've tried other insertion
> methods
> other than SetStringItem -- though perhaps not the 'right' one.
>
> Any insights as to how to fix this -- or documentation that will clarify
> my confusion would be appreciated!
>
> -frank





More information about the Python-list mailing list