Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a program written in C++ with WinApi functions (I am not using MFC). In this program I have a treeview (elements can be added or deleted) and I want to solve a problem: I want to know exactly which item was selected. Please help.

Example:
+Color
 -Red
 -Blue
+Ground
 -sldfs
 -sdfsdfafsd

Return: Color red (or something else)
Posted
Updated 15-Jun-10 10:24am
v3

Something like this
// Get a handle to the selected item
HTREEITEM hSelectedItem = TreeView_GetSelection(hwnd);

if (hSelectedItem == NULL) // Nothing selected
    return;

// Now get the text of the selected item
TCHAR buffer[128];

TVITEM item;
item.hItem = hSelectedItem;
item.mask = TVIF_TEXT;
item.cchTextMax = 128;
item.pszText = buffer;
if (TreeView_GetItem(hwnd, &item))
{
    cout << item.pszText << " is selected" << endl;
}
 
Share this answer
 
v2
You would better take a look to control documentation [^].
 
Share this answer
 
Thanks for the ansver. They are very helped me.
 
Share this answer
 
Thanks..... it helps me :)
 
Share this answer
 

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