Hi,
I've a wx.gizmos.TreeListCtrl with 3 column, when I click on a row
I would want to recover the value of the first column that is a number
(is a pk of a record).
On EVT_TREE_SEL_CHANGED I make this
def OnSelChange(self, event):
if event.GetId() == ID_MY_TREE :
try:
item = self.treeDocuments.GetItemText(event.GetItem())
id = int(str(item))
except:
pass
the obscene line
id = int(str(item))
derives from the fact that GetItemText return me an unicode value.
Does a simpler and direct way exist for making this thing?
The control deals with string values (well, unicode but for this question that doesn't really matter). If you want to treat one of those strings as a number then you're going to have to convert it. The control is not going to automagicaly notice that the string is "1234" and return it to you as a number instead. That's what programmers are for.
You don't, however, need to convert to a string first before converting to an integer. The int() type is smart enough to convert unicode values too.
>>> int(u"1234")
1234
Besides an event type EVT_LIST_ITEM_SELECTED exists for TreeListCtrl?
You should be able to use the same event binder, the TLC emits the same events as wx.ListCtrl if I remember correctly.