[wxPython-users] Re: problem getting correct treeCtrl item id
Jeff Peck
jpeck at fedex.com
Thu Apr 12 18:16:42 PDT 2007
Jeff,
Just a shot in the dark, but in the code to OnMenuItem you are calling
GetItemSelection() - shouldn't that be GetSelection()?
Jeff
Christian K wrote:
> Jeff Peery wrote:
>
>> hello, I am using the below code to add items to a treeCtrl. I have teh user create a new folder to which they can add items. If they right click on the folder a popup menu appears with an option to add a new item to the folder they just created. so it all works ok except that the tree item id that I saved (self.new_item) isn't the same as the one I get when I select the item using GetSelection(). Shouldn't they be the same? thanks.
>>
>> Jeff
>>
>> def add_folder(self):
>> # add item to the root and save its item id
>> self.new_item = self.treeCtrl.AppendItem(root_item, 'New Folder', 3, -1)
>> # add a item to a popup menu
>> new_id = wx.NewId()
>> self.menu.append(help='', id=new_id, kind=wx.ITEM_NORMAL, text='create new item')
>> self.Bind(wx.EVT_MENU, self.OnMenuItem, id=new_id
>>
>> def OnMenuItem(self, event):
>> hndl = self.treeCtrl.GetItemSelection()
>>
>> when I get here I want to know if the user selected the newly created menu item, but if I pick the new menu item and check the item they are different ie:
>> hndl != self.new_item
>>
>
> I can't explain the backgrounds why your approach does not work but as far as I
> remember the tree items are kind of dynamic. The way to go is to use
> PySetData/PyGetData to store/get a unique identifier for each tree item you create.
>
> Christian
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org
>
>
>
More information about the wxpython-users
mailing list