[wxPython-users] identify/track an item in a TreeCtrl

Andrea Gavana andrea.gavana at gmail.com
Mon Dec 3 03:07:02 PST 2007


Hi Harry,

On Dec 3, 2007 10:59 AM, Pan Xingzhi wrote:
>     Is there a way to identify/track an item in a TreeCtrl? This action
> typically takes place in an event handler where the exact "source" of the
> event is needed.
>     I tried event.GetItem(), but the returned TreeItemId instance is not the
> one returned by AppendItem. However their m_pItem property looks the same.
> Can I use that?
>     I read the source code in the wxPython demo. It just retrieves the text
> of the item using GetItemText(event.GetItem()). Though the TreeItemId
> instance is changed, we can still get the same information (text, color...)
> of the item. There must be some magic behind scene but I'm just confused.

The TreeItemId generated by the C++ wxWidgets code is an
evanescent/ghostly entity which may or may not change depending on
what you do with the TreeCtrl. Using event.GetItem() will almost
surely not returns the same TreeItemId as AppendItem. Depending on
which are your needs, you might only use the item returned by
event.GetItem(), or store some particular identifier into the item
PyData (using SetPyData/GetPyData), or maybe use the m_pIten property
(but I never used it and I don't even know what it's for). Or, as a
last resort, you might switch to CustomTreeCtrl, which doesn't use any
C++ :-D.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/




More information about the wxpython-users mailing list