Click here to Skip to main content
15,917,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I want to get the selected item from a tree view for which I am using
the 'GetSelectedItem()' method. On OnNMClickTree1() event i am trying to get the selected item.

my code is like:
C++
HTREEITEM m_Sel_Item = m_FirstTreeCtl.GetSelectedItem();


but this method is first time it's sending the last tree element as selected text. And if select any one item in the tree it is giving previously selected item. Can any tell me how to get selected item in the tree control?
Posted
Updated 9-Feb-11 16:54pm
v3
Comments
Prerak Patel 10-Feb-11 9:15am    
Did you try this article http://www.codeproject.com/KB/tree/CColumnTreeCtrl.aspx?msg=2693088?
savita_Bgm 15-Feb-11 0:38am    
Thanks, I got it.

On which event you are trying to get selected item?
You can get it on OnSelchangedTreectrl.

http://www.codersource.net/mfc/mfc-tutorials/mfc-tree-usage-and-example.aspx[^]
http://www.functionx.com/visualc/controls/treectrl.htm[^]
 
Share this answer
 
Comments
savita_Bgm 11-Feb-11 1:26am    
But in my application the GeselectedItem() is not taking current selected item, it is taking previos selected item
Please try following i thik your problem will solve

Private Sub TreeView1_Click()
lblCurrentRecord.Caption = TreeView1.SelectedItem.Text
End Sub
 
Share this answer
 
Comments
Nithin Sundar 9-Feb-11 6:12am    
Please edit your answer and convert it into a C++ equivalent code. The question is tagged as MFC.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900