Question about right click in a CTreeControl!

  • Thread starter Thread starter Lars Grøtteland
  • Start date Start date
L

Lars Grøtteland

Hello!


Having problems about right clicking on an item in a tree control. The item
that is clicked on is not the right one.
If I have three items in a tree.
Here is my problem. I click on the first item with normal click. I click on
the third item with the right click mouse. In this event I had a messagebox
telling me which item is selected, and this one comes out with the first
item no mather what. I also tried to get into the OnSelchangedItemfieldtree
function - but with no luck.

How can I right click on the third one and get its name out of it? Does
anyone know?
 
I guess u r using GetSelectedItem() within NM_RCLICK handler. The default
behaviour of TreeCtrl does'nt select an item on getting RClick.

Try the following code, it worked for me

void CMyTreeCtrl::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
CPoint pt;
GetCursorPos(&pt);
ScreenToClient(&pt);

UINT flags;
HTREEITEM hItem = HitTest( pt, &flags );
if ( hItem &&
flags & TVHT_ONITEM )
{
MessageBox( GetItemText(hItem) );
}

*pResult = 0;
}


hth
Thangaraj A.L.
 
if you are trying to display selected item in OnRButtonDown before anything
happens then previous one would be still selected... If you are doing that
then perhaps you should put the same msg box on OnRButtonUp..
 
WOW
Thanks very much!

Could I ask you another one. If I drag an item in the tree - I would like it
to change place with that one I drag it over? How do I do that?


- Lars
 
Back
Top