Question about right click in a CTreeControl!

  • Thread starter Lars Grøtteland
  • 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?
 
T

Thangaraj

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.
 
N

Neel Roy

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..
 
L

Lars Grøtteland

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Disabled CTreeControl question 1
Right Click question 15
CTreeCtrl 1
Before right click: 1
Mouse Right Click Problems 2
Right Click - Disable item 1
Cells Right Click Menu Problem 2
Right Click Selection 2

Top