In my database I have a table with a guid and a name field. The guid is my primary key. I can query the table and populate the tree using the “Name” data field. My problem is that the name field is not unique so it’s difficult to track which guid + name combination it is. For example, my treeview might look something like this:
-Cities in America
|
-Cities in Oregon
|
+Milwaukee
+Salem
|
-Cities in Wisconsin
|
-Milwaukee
-Madison
The city of Milwaukee in Oregon has a different guid than the one in Wisconsin. When a user clicks on either Milwaukee, how can I keep track of which one was selected? I’ll need to know the guid of that selection so I can requery the database and grab other fields pertaining to that city.
When you insert an item into the treeview, you can include an lParam. It’s only a 32-bit item, so you can’t store your GUID directly, but you could (for one example) create an array of GUIDs as you insert items into the tree, and store the index into the array in the lParam.
When the user clicks on an item, that will select the item and you’ll receive a
TVN_SELCHANGEDmessage, which will contain (among other things) a pointer to aTVITEM, which will contain the lParam you inserted as part of the item. You can then use that to look up your GUID.