Skip to main content
gamedev.net
🔒 Locked

Problem with Tree View

Started by BlueDev 2 replies 750+ views
Original Post
BlueDev
BlueDev
Hello, I am trying to do a simple task by finding out which item is Selected, more than that, the selected number. For example the first item will be 0, the next 1. I am using the following code so far:
int num;
HWND hWnd, hTree;
HTREEITEM hItem, Selected;

// num equals selected number


hTree = GetDlgItem(hWnd, IDTREE);

Selected=(HTREEITEM)SendMessage(hTree,TVM_GETNEXTITEM,TVGN_CARET,(LPARAM)Selected);
num = TreeView_GetItem(hTree, Selected);
Now when I do that they all come out to be 1 for some reason, maybe cause TreeView_GetItem returns BOOL. Is there a function I can use that will actually work as in the first item selected is 0, the third item 3 and so on? Thank your for your time. - BlueDev
   BlueDev Net [edited by - BlueDev on September 9, 2003 9:50:49 PM]
[/quote]
JY
JY
I would be surprised if that even compiles, does it? GetItem expects a pointer to a TV_ITEM structure in order to return information about the item pointed to by the HTREEITEM.

The items are not numbered from 0 upwards as they are in a list box - the HTREEITEM is the unique identifier for each item. If you do really want to number them you can use SetItemData to associate a value with each item, which you will have to do when you insert the items into the tree.



"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
BlueDev
BlueDev
Ok sounds like a good idea, do you know if SetItemData works with Win32 because I saw lots on MFC but I havent goten that far yet. I believe it is possible but no one documents on it, is it truly possible?

- BlueDev
[/quote]
llyod
llyod
Here''s an article on Treeview in pure Win32: clicky

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.