Tree Control - finding item selected

I have a tree control which displays a whole sort of options. I'm using the function to work out when the user has clicked the mouse button and then using HitTest to work out which option it was exactly. Now what i would like to know is how can i relate this information to a linked-list i have that has all those options in it. ie from what the user has clicke don, how can i know which option it is in the linked list??? note that i can't do a string compare on the name of the option. Thanks
Who is Participating?
krmjConnect With a Mentor Commented:
I'm glad it worked out for you.
Try this:

When you build your tree associate each object in your list link with its corresponding tree item by setting the item data to the object pointer. You can do this when you add the item by setting lParam to the object pointer:

TV_INSERTSTRUCT      tvInsert;

//      Set up the insert structure
tvInsert.item.mask = TVIF_TEXT | TVIF_PARAM;
tvInsert.item.pszText = LPSTR_TEXTCALLBACK;
tvInsert.item.iImage =
tvInsert.item.iSelectedImage =
tvInsert.item.lParam = (LPARAM)MyObjPointer;

//Add the item

After you've done this you can get the lParam back and cast it to your object pointer when the user selects a new item in the tree.
Since this is MFC, you can use:

SetItemData and GetItemData of the tree ctrl.

Call this function to set the 32-bit application-specific value associated with the specified item.
Call this function to retrieve the 32-bit application-specific value associated with the specified item.

chris_kabukiAuthor Commented:
Thanks krmj.....exactly what i needed, one thing...can u put in an answer so i can give you the points...thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.