[wxPython-users] Issues setting items for a multicolumn listctrl

Robin Dunn robin at alldunn.com
Mon Oct 1 13:01:18 PDT 2007


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!





More information about the wxpython-users mailing list