How to GetItemText from a TreeView using right click?
-
Presently, I manage to do that when I first click on the left mouse button to select the HTREEITEM and then click on the right to bring up a message box showing the value of selected item text. How to GetItemText from a tree view using right click without using the left one first? Thanks. YC
-
Presently, I manage to do that when I first click on the left mouse button to select the HTREEITEM and then click on the right to bring up a message box showing the value of selected item text. How to GetItemText from a tree view using right click without using the left one first? Thanks. YC
To your class derived from TreeView add to the message handler //{{AFX_MSG(CMyTreeView) afx_msg void OnRButtonDown(UINT nFlags, CPoint point); //}}AFX_MSG Implement the function OnRButtonDown as following void CMyTreeView::OnLButtonDown(UINT nFlags, CPoint point) { UINT uFlags; HTREEITEM hItem = GetTreeCtrl().HitTest(point, &uFlags); if ((hItem != NULL) && (uFlags & TVHT_ONITEM)) { CString strText = GetTreeCtrl().GetItemText(hItem); AfxMessageBox(strText); } }