Get tree item
-
I have placed TVINSERTSTRUCT as a memeber in a self-defined struct, as follows: struct MyStruct { int data; TVINSERTSTRUCT tvins; // etc... } When the user clicks on button A, and having selected a particular tree item, i want to amend the value of the member 'data' which is in the same struct as the selected tree item. I tried to use GetSelectedItem(), bt it returns a HTREEITEM. How do i know which node doe sit belong too? Thanks in advance. :rolleyes:
-
I have placed TVINSERTSTRUCT as a memeber in a self-defined struct, as follows: struct MyStruct { int data; TVINSERTSTRUCT tvins; // etc... } When the user clicks on button A, and having selected a particular tree item, i want to amend the value of the member 'data' which is in the same struct as the selected tree item. I tried to use GetSelectedItem(), bt it returns a HTREEITEM. How do i know which node doe sit belong too? Thanks in advance. :rolleyes:
I think you are thinking about it backwards. It is probably easier to add your data to the TreeView items. You can accomplist this by using the lParam in the TVITEM. Whenever an item is selected, handle the TVN_SELCHANGED message for your treeview and retrieve the data and modify accordingly. Mike Some Code follows: HTREEITEM tvAddItem( HTREEITEM hParent, LPSTR szText, HTREEITEM hInsAfter, int iImage, LPVOID pvData ) // pvData would just be your MyStruct * { HTREEITEM hItem; TVITEM tvI = {0}; TVINSERTSTRUCT tvIns = {0}; // The pszText, iImage, and iSelectedImage members are filled out. // make sure we set the flag for TVIF_PARAM if( iImage == -1 ) { tvI.mask = TVIF_TEXT | TVIF_PARAM; } else { tvI.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; } tvI.pszText = szText; tvI.cchTextMax = lstrlen (szText); tvI.iImage = iImage; tvI.iSelectedImage = iImage; tvI.lParam = (LPARAM) pvData; tvIns.item = tvI; tvIns.hInsertAfter = hInsAfter; tvIns.hParent = hParent; // Insert the item into the tree. hItem = TreeView_InsertItem( iv_ctlTreeView.m_hWnd, &tvIns ); return( hItem ); } // update the data from the TreeView in the SELCHANGED event // selchange WM_NOTIFY, TVN_SELCHANGED LPNMTREEVIEW pnTree = (LPNMTREEVIEW) lParam; MyStruct *pMyStruct; pMyStruct = (MyStruct *) pnTree->itemNew.lParam;