Link to home
Start Free TrialLog in
Avatar of chris_kabuki
chris_kabuki

asked on

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
Avatar of krmj
krmj

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
InsertItem(&tvInsert);

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.

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


Avatar of chris_kabuki

ASKER

Thanks krmj.....exactly what i needed, one thing...can u put in an answer so i can give you the points...thanks
ASKER CERTIFIED SOLUTION
Avatar of krmj
krmj

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial