Search code examples
pythonwxpythonlistctrl

ListCtrl - wxPython / Python


My question is if we can assign/bind some value to a certain item and hide that value(or if we can do the same thing in another way).

Example: Lets say the columns on ListCtrl are "Name" and "Description":

self.lc = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
self.lc.InsertColumn(0, 'Name')
self.lc.InsertColumn(1, 'Description')

And when I add a item I want them to show the Name parameter and the description:

num_items = self.lc.GetItemCount()
        self.lc.InsertStringItem(num_items, "Randomname")
        self.lc.SetStringItem(num_items, 1, "Some description here")

Now what I want to do is basically assign something to that item that is not shown so I can access later on the app.

So I would like to add something that is not shown on the app but is on the item value like:

hiddendescription = "Somerandomthing"

Still didn't undestand? Well lets say I add a button to add a item with some other TextCtrls to set the parameters and the TextCtrls parameters are:

"Name"

"Description"

"Hiddendescription"

So then the user fills this textctrls out and clicks the button to create the item, and I basically want only to show the Name and Description and hide the "HiddenDescription" but to do it so I can use it later.

Sorry for explaining more than 1 time on this post but I want to make sure you understand what I pretend to do.


Solution

  • the wxListCtrl lets you associate arbitrary data with an item, that will not be displayed - read the docs for the following methods:

    SetItemData

    GetItemData

    FindItemData

    The wxListItem class also has GetData and SetData methods.