wxpythonlistitemlistctrl

wxPython wx.ListCtrl with specific data


I want to add to wx.ListCtrl from wxPython items that have a specific ID associated to them. How can I achieve that? Actually, how do you associate any data to a specific ListCtrl item?


Solution

  • I would create a dictionary where the keys are the IDs and then use the ListCtrl's SetItemData to associate the key the list control item. Then you can use the GetItemData method to retrieve the ID and use that with your dictionary to get the data.

    Or you could use the ListCtrlPyDataMixin which would make this a bit easier:

    Personally, I really like using ObjectListView instead of the straight wx.ListCtrl. Here's a tutorial on how it works:

    And as @nepix32 mentioned, you could also use the wx.DataViewCtrl, if you have wxPython 2.9 or newer.