LPARAM associated data in TVITEM in TreeCtrl
-
If someone can explain the following I would appreciate it. I have a simple Tree control in which I need to associate data with individual items in the tree. The 32 bit LParam seems like an easy place to place an identifier that I can then use to lookup the assoicated data in a secondary array (or what ever). When I try to directly use this field it appears to always be blank (zero). But when I use the SetItemData function with the item handle returned in from the InsertItem function all works fine. HTREEITEM pItem = m_ProdTree.InsertItem("My Text",pRoot,NULL); DWORD MyNum=nnn; m_ProdTree.SetItemData(pPar,MyNum); Doesn't the SetItemData/GetItemData use the LParam field?? Thanks Mike
-
If someone can explain the following I would appreciate it. I have a simple Tree control in which I need to associate data with individual items in the tree. The 32 bit LParam seems like an easy place to place an identifier that I can then use to lookup the assoicated data in a secondary array (or what ever). When I try to directly use this field it appears to always be blank (zero). But when I use the SetItemData function with the item handle returned in from the InsertItem function all works fine. HTREEITEM pItem = m_ProdTree.InsertItem("My Text",pRoot,NULL); DWORD MyNum=nnn; m_ProdTree.SetItemData(pPar,MyNum); Doesn't the SetItemData/GetItemData use the LParam field?? Thanks Mike
-
Maybe you have not set the flags in the
TVITEM
structure correctly? Try to debug into theSetItemData()
member function and look how MFC does it. Then you can do it the same way. -
If someone can explain the following I would appreciate it. I have a simple Tree control in which I need to associate data with individual items in the tree. The 32 bit LParam seems like an easy place to place an identifier that I can then use to lookup the assoicated data in a secondary array (or what ever). When I try to directly use this field it appears to always be blank (zero). But when I use the SetItemData function with the item handle returned in from the InsertItem function all works fine. HTREEITEM pItem = m_ProdTree.InsertItem("My Text",pRoot,NULL); DWORD MyNum=nnn; m_ProdTree.SetItemData(pPar,MyNum); Doesn't the SetItemData/GetItemData use the LParam field?? Thanks Mike
Just to document: I was not setting the mask correctly. I had just set the mask to TVIF_TEXT and had not added the TVIF_PARAM. TVINSERTSTRUCT MyInsert; MyInsert.hParent=NULL; MyInsert.hInsertAfter=NULL; MyInsert.item.mask=TVIF_TEXT|TVIF_PARAM; // <<< HERE // The mask defines what is valid !! MyInsert.item.pszText=_T("A->Root"); MyInsert.item.lParam=(LPARAM)MyDataValue; HTREEITEM TVI_MyItem = m_Tree.InsertItem(&MyInsert);