Treeview selected item index
is the开发者_高级运维re anyway to get the index of selected tree view node or do they even have one?
Since you're asking for "index" only to be able to find data associated with this item you should know that tree control can hold your data. Every item (TVITEM
struct) has a lParam
member that you can use for this.
If you really need a container do as avakar suggested. Use HTREEITEM
as key.
Something like this:
Selected=(HTREEITEM)SendDlgItemMessage(hWnd,IDC_TREE1,
TVM_GETNEXTITEM,TVGN_CARET,(LPARAM)Selected);
if(Selected==NULL)
{
MessageBox(hWnd,"No Items in TreeView","Error",
MB_OK|MB_ICONINFORMATION);
break;
}
Comes from here
There's no such thing, because such an index can be defined in many ways.
If you collapse and expand the nodes, is the selected index going to change, or stay constant?
To get this functionality, you'll have to roll your own algorithm with whatever set of rules you want. Or, simply go by the selected node as shown (this is much more common).
精彩评论