Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Get tree item

Get tree item

Scheduled Pinned Locked Moved C / C++ / MFC
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hearties
    wrote on last edited by
    #1

    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:

    M 1 Reply Last reply
    0
    • H hearties

      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:

      M Offline
      M Offline
      MikeG 0
      wrote on last edited by
      #2

      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;

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups