Issues setting items for a multicolumn listctrl

Inserting items with:

            if col:
                self.InsertColumnItem(col, item)
            else:
                self.InsertItem(item)

In a loop. The items have Text associated with them, but once they've
been added, only the first item, added via InsertItem has Text. The
others have u'' as the Text. I retain a reference to the actual
ListItem object and I can still call item.Text afterwards and verify
that it has Text, but the item in the ListCtrl does not.

What's going on here?

Thanks,
-Dan

Dan Eloff wrote:

Inserting items with:

            if col:
                self.InsertColumnItem(col, item)
            else:
                self.InsertItem(item)

In a loop. The items have Text associated with them, but once they've
been added, only the first item, added via InsertItem has Text. The
others have u'' as the Text. I retain a reference to the actual
ListItem object and I can still call item.Text afterwards and verify
that it has Text, but the item in the ListCtrl does not.

What's going on here?

You are mixing apples and oranges... In report mode an item is the whole row so first you insert the item and then you can set the text for the other columns of the same item. Since the API of wx.ListCtrl is so strange (thank you Microsoft) this fact can easily be confused or lost. So normally you would use one of the the Insert*Item methods to add the new item and then one of the Set*Item methods to set the text for the other columns of the same item. Since you are using the plain Item version of the methods then you can save the return value of InsertItem so you know what the ID (the index) of the item is, and then set the ID and col in the wx.ListItem you pass to SetItem for the other columns.

The InsertColumItem is for inserting a new column for the whole wx.ListCtrl.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Dan,

From: Dan Eloff [mailto:dan.eloff@gmail.com]
Sent: Monday, October 01, 2007 1:36 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Issues setting items for a multicolumn listctrl

Inserting items with:

            if col:
                self.InsertColumnItem(col, item)
            else:
                self.InsertItem(item)

In a loop. The items have Text associated with them, but once
they've been added, only the first item, added via InsertItem
has Text. The others have u'' as the Text. I retain a
reference to the actual ListItem object and I can still call
item.Text afterwards and verify that it has Text, but the
item in the ListCtrl does not.

What's going on here?

Thanks,
-Dan

I use InsertStringItem() to insert an item and SetStringItem() method to
put text into specific "columns" in the wx.ListCtrl. The WIA book says
that InsertItem is used internally by the list control to manage
information. I don't really understand it all, but I don't think it's what
you want. It seems to retain previously created items in memory and that's
why I assume you can query your text. If you have the book, see page 403.

Mike

···

-----Original Message-----