|
-
March 30th, 1999, 07:14 PM
#1
CTreeCnrl?
I set-up a message handler to handle a single click in a tree control. I'm trying to get the item text with a single
click. A member variable is associated with the tree (m_tree). A member variable is associated with an edit box in
the dialog (m_text).
The problem is, when I click on the first item nothing happens. When I click on the second item, the first item shows
up. Click on the third ... get the second, and so on. It seems that I'm not really selecting until another mouse
event click (two clicks on the same item will get that item's text).
How do I get the text of the item on the first click?
Here's the code I'm using.
void CMyDlg::OnClickTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
HTREEITEM hItem=m_tree.GetSelectedItem();
if(hItem)
{
m_text=m_tree.GetItemText(hItem);
UpdateData(FALSE);
}
*pResult = 0;
}
-
March 31st, 1999, 12:17 AM
#2
Re: CTreeCnrl?
Your OnClick comes to soon, ie before the new selection takes place. Try the TVN_SELCHANGED message of CTreeCtl.
Hope for help
Rudolf
-
April 1st, 1999, 02:05 PM
#3
Re: CTreeCnrl?
My guess is that you are handling the message TVN_SELCHANGING, which is sent when the selection in the tree is about to change. So in your handler, when you do a GetSelectedItem, you get a handle to the previous node. You should handle the TVN_SELCHANGED message instead, which will be sent after the selection in the tree control has changed.
-
May 4th, 1999, 04:28 AM
#4
Re: CTreeCnrl?
The problem is that you get the selected item each time you click. Your click message handling is coming too soon and the selected item is always the previous one. Try to handle SEL_CHANGING message instead.
Another solution if you use MFC and a TreeView object is to get the mouse coordinates each time you click and ask the TreeCtrl which item is under the mouse.
void MyTreeView::OnClick(UINT Flags, CPoint point)
{
HTREEITEM hItem = TreeCtrl.HitTest(point);
// can be null
...
...
}
Hope it helps
C++ developer
Faculté de Médecine
27 Bd Jean Moulin
13385 Marseille cedex 05
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|