We help IT Professionals succeed at work.

CTreeCtrl edit label question

na95enm
na95enm asked
on
Hi!

I have a MFC app with a tree control. How can I test if a certain HTREEITEM is being edited(through f2 or using mouse). I need a function like this : IsBeeingEdited(HTREEITEM);

/Erik
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Hi na95enm,

when the user starts editing a label a TVN_BEGINLABELEDIT notification
message is sent to the tree's parent window, when editing ends a
TVN_ENDLABELEDIT notification message is sent to the tree's parent
window.

So, you can declare a HTREEITEM variable which is initially set to NULL,
set it to the given ((LPNMTVDISPINFO*)lParam)->item.hItem in message
handler for TVN_BEGINLABELEDIT and set it back to NULL in handler
for TVN_ENDLABELEDIT.

Then you can implement your function IsBeeingEdited( HTREEITEM ) by
simply comparing the passed HTREEITEM with the stored one.

BTW, you can handle this either in the class of the parent window (i.e. a dialog)
or in a CTreeCtrl-derived class using message reflection ... what you use
depends on your needs, i.e. if you want it to be re-usable with other dialogs.

hope that helps,

ZOPPO

Author

Commented:
Hi ZOPPO!

Thankyou for your help. I will accept it as an answer.
I implemented it like this before reading your comment :

CEdit* pEdit = m_TreeCtrl.GetEditControl();
if (pEdit)
  //Edit in action  
else
  //Edit not in action  

This will work because only one item can be edited at same time.