Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Tree Control - finding item selected

Posted on 1999-06-25
Medium Priority
Last Modified: 2013-11-20
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
Question by:chris_kabuki
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 1308056
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.

Expert Comment

ID: 1308057
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.


Author Comment

ID: 1308058
Thanks krmj.....exactly what i needed, one thing...can u put in an answer so i can give you the points...thanks

Accepted Solution

krmj earned 800 total points
ID: 1308059
I'm glad it worked out for you.

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question