views:

355

answers:

3

Hello everyone. 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.

A: 

You could always set the width of the hidden column to zero, that might accomplish what you want. I just tried it in a C++ (non-wx) program and it worked fine.

Mark Ransom
Well, thanks for your help and it would be a good idea if there wasn't a little problem, when I go to resize the Description column it appears to resize either Description column and the hiddendescription column revealing the information... But thanks anyway!
Francisco Aleixo
+3  A: 

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.

Dave Kirby
I did not know about this, thanks alot for your help!
Francisco Aleixo
+2  A: 

Instead of using the ListCtrl as your data structure, you could keep a separate list/dict of objects that contain all the information you want and refresh the ListCtrl from your other data structure.

For example:

class MyObject(object):
    def __init__(self, name, description, hidden_description):
        self.name = name
        self.description = description
        self.hidden_description = hidden_description

Then in your application:

def __init__(self):
    self.my_items = {}
    self.lc = wx.ListCtrl(self, -1, style=wx.LC_REPORT)
    self.lc.InsertColumn(0, 'Name')
    self.lc.InsertColumn(1, 'Description')

def addItemToMyListCtrl(self, name, description, hidden):
    new_item = MyObject(name, description, hidden)
    self.my_items[name] = new_item
    self.lc.Append((new_item.name, new_item.description))

Then when you want to use your additional data you can just look up the correct item in the dictionary and your data will be there.

tgray
Didn't think about this, thanks alot, i'll give a try to this method!
Francisco Aleixo