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. How can I select a node in a treeview

How can I select a node in a treeview

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 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.
  • A Offline
    A Offline
    Alex Cutovoi
    wrote on last edited by
    #1

    Hi fellows. I have a treeview(populated) and I would like to select a single node I have this code: case WM_NOTIFY: { TV_ITEM tempTvItem; char cTemp[256]=""; unsigned int uiVal = 0; LPNMHDR notifyMessageStruct = (LPNMHDR)lParam; if(notifyMessageStruct->hwndFrom == treeViewHwnd) { if(notifyMessageStruct->code == NM_CLICK) { nodeSelected = (HTREEITEM)SendDlgItemMessage(treeViewHwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); //itoa((int)nodeSelected, cText, 10); tempTvItem.mask = TVIF_TEXT|TVIF_HANDLE; tempTvItem.hItem = nodeSelected; tempTvItem.pszText = cTemp; tempTvItem.cchTextMax = 256; SendMessage(treeViewHwnd, TVM_GETITEM, 0, (LPARAM)&tempTvItem); MessageBox(NULL, tempTvItem.pszText, "", MB_OK); ... My problem is that the select part. The node isn`t selected and in the MessageBox nothing is shown. What`s the problem? I want when I select the node it remais highlighted and selected.

    A 1 Reply Last reply
    0
    • A Alex Cutovoi

      Hi fellows. I have a treeview(populated) and I would like to select a single node I have this code: case WM_NOTIFY: { TV_ITEM tempTvItem; char cTemp[256]=""; unsigned int uiVal = 0; LPNMHDR notifyMessageStruct = (LPNMHDR)lParam; if(notifyMessageStruct->hwndFrom == treeViewHwnd) { if(notifyMessageStruct->code == NM_CLICK) { nodeSelected = (HTREEITEM)SendDlgItemMessage(treeViewHwnd, IDC_TREE1, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); //itoa((int)nodeSelected, cText, 10); tempTvItem.mask = TVIF_TEXT|TVIF_HANDLE; tempTvItem.hItem = nodeSelected; tempTvItem.pszText = cTemp; tempTvItem.cchTextMax = 256; SendMessage(treeViewHwnd, TVM_GETITEM, 0, (LPARAM)&tempTvItem); MessageBox(NULL, tempTvItem.pszText, "", MB_OK); ... My problem is that the select part. The node isn`t selected and in the MessageBox nothing is shown. What`s the problem? I want when I select the node it remais highlighted and selected.

      A Offline
      A Offline
      Ali Rafiee
      wrote on last edited by
      #2

      Where did you get IDC_TREE1 from?? If you are using a CTreeView view, why aren't you using GetTreeCtrl()->SelectItem(...);? AliR. Visual C++ MVP

      A 1 Reply Last reply
      0
      • A Ali Rafiee

        Where did you get IDC_TREE1 from?? If you are using a CTreeView view, why aren't you using GetTreeCtrl()->SelectItem(...);? AliR. Visual C++ MVP

        A Offline
        A Offline
        Alex Cutovoi
        wrote on last edited by
        #3

        I`m not using CTreeView, I`m creating the treeview with CreateWindowEx function. and in the HMENU part I include the IDC_TREE1 like the ID of the window..... Like this: treeViewHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "theTreeView", WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT, 0, 0, 400, myRect.bottom, hwnd, (HMENU)IDC_TREE1, hCurrentInstance, NULL); -- modified at 17:19 Wednesday 19th July, 2006

        A 1 Reply Last reply
        0
        • A Alex Cutovoi

          I`m not using CTreeView, I`m creating the treeview with CreateWindowEx function. and in the HMENU part I include the IDC_TREE1 like the ID of the window..... Like this: treeViewHwnd = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "theTreeView", WS_CHILD|WS_VISIBLE|TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT, 0, 0, 400, myRect.bottom, hwnd, (HMENU)IDC_TREE1, hCurrentInstance, NULL); -- modified at 17:19 Wednesday 19th July, 2006

          A Offline
          A Offline
          Ali Rafiee
          wrote on last edited by
          #4

          In that case try this nodeSelected = (HTREEITEM)SendMessage(treeViewHwnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); AliR. Visual C++ MVP

          A 1 Reply Last reply
          0
          • A Ali Rafiee

            In that case try this nodeSelected = (HTREEITEM)SendMessage(treeViewHwnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)nodeSelected); AliR. Visual C++ MVP

            A Offline
            A Offline
            Alex Cutovoi
            wrote on last edited by
            #5

            Ali unhappilly, this code doesn`t work too.... I`m almost changing to TreeView_SelectItem....

            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