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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Setting Children Nodes of Tree View Based on Parent Node [modified]

Setting Children Nodes of Tree View Based on Parent Node [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpjavascriptdata-structures
15 Posts 3 Posters 2 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.
  • L led mike

    I read your post a couple times and I have no idea what you are trying to do. Have you read any beginner material for working with windows tree controls like this CodeProject article[^] That's only one, there are tens of CP articles using the Tree Control

    led mike

    S Offline
    S Offline
    Stuck At Zero
    wrote on last edited by
    #4

    I am using a tree view with 16,384 nodes (2048 nodes per root node). I'm trying to allow a user to select or deselect a node anywhere on the tree view such that when a node is selected or deselected, all of its children nodes would mirror that selection.

    1 Reply Last reply
    0
    • M Mark Salsbery

      There is a lot of notifications sent by a tree control. Do you really want your code to execute on every one of them? Also, what are you doing with the item check state, and how does that apply to the selected item? Tree View Controls[^] Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      S Offline
      S Offline
      Stuck At Zero
      wrote on last edited by
      #5

      I originally tried doing a message map of the OnNotify that I saw elsewhere through googling, but there does not seem to be a notification appropriate for what I want to do. I was using item check state to see if the node which has the user's focus was checked or not. The idea was that once a user clicks on a node within the tree view, OnNotify would fire off and it would check to see if the node was selected or not. Depending on its state, I would either select or deselect all decedent nodes from the node the user selected.

      M 1 Reply Last reply
      0
      • S Stuck At Zero

        I originally tried doing a message map of the OnNotify that I saw elsewhere through googling, but there does not seem to be a notification appropriate for what I want to do. I was using item check state to see if the node which has the user's focus was checked or not. The idea was that once a user clicks on a node within the tree view, OnNotify would fire off and it would check to see if the node was selected or not. Depending on its state, I would either select or deselect all decedent nodes from the node the user selected.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #6

        What about something like this:

        BOOL CViewFilter::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
        {
        if (wParam == IDC_TREE1)
        {
        NMHDR *pHdr = (NMHDR *)lParam;

        if (pHdr->code == TVN\_SELCHANGED)
        {
          LPNMTREEVIEW pNMTreeView = (LPNMTREEVIEW)lParam;
        
          // pNMTreeView->itemNew is the new selected item (TVITEM)
          // pNMTreeView->itemNew.hItem is the new selected item's HTREEITEM
        
          if (pNMTreeView->itemNew.hItem)
          {
            if (m\_filterTreeCtrl.GetCheck(pNMTreeView->itemNew.hItem))
            {
              // Select All Subsequent Children Nodes
              SetDecendentNodesOn(pNMTreeView->itemNew.hItem);
            }
            else
            {
              // Deselect All Subsequent Children Nodes
              SetDecendentNodesOff(pNMTreeView->itemNew.hItem);
            }
          }
        
          return TRUE;
        }
        

        }

        return CDialog::OnNotify(wParam, lParam, pResult);
        }

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        S 1 Reply Last reply
        0
        • M Mark Salsbery

          What about something like this:

          BOOL CViewFilter::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
          {
          if (wParam == IDC_TREE1)
          {
          NMHDR *pHdr = (NMHDR *)lParam;

          if (pHdr->code == TVN\_SELCHANGED)
          {
            LPNMTREEVIEW pNMTreeView = (LPNMTREEVIEW)lParam;
          
            // pNMTreeView->itemNew is the new selected item (TVITEM)
            // pNMTreeView->itemNew.hItem is the new selected item's HTREEITEM
          
            if (pNMTreeView->itemNew.hItem)
            {
              if (m\_filterTreeCtrl.GetCheck(pNMTreeView->itemNew.hItem))
              {
                // Select All Subsequent Children Nodes
                SetDecendentNodesOn(pNMTreeView->itemNew.hItem);
              }
              else
              {
                // Deselect All Subsequent Children Nodes
                SetDecendentNodesOff(pNMTreeView->itemNew.hItem);
              }
            }
          
            return TRUE;
          }
          

          }

          return CDialog::OnNotify(wParam, lParam, pResult);
          }

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          S Offline
          S Offline
          Stuck At Zero
          wrote on last edited by
          #7

          It only works on the very first mouse click for the first root node only. Decendent nodes nor any of the other root nodes have any effect on the OnNotify. After the first mouse click to either select / deselect the 1st root node, that root node then behaves like the other root nodes.

          M 1 Reply Last reply
          0
          • S Stuck At Zero

            It only works on the very first mouse click for the first root node only. Decendent nodes nor any of the other root nodes have any effect on the OnNotify. After the first mouse click to either select / deselect the 1st root node, that root node then behaves like the other root nodes.

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #8

            Do you call SetCheck anywhere? How do the items get their check state set? What's happening in your SetDecendentNodes functions? Have you put a breakpoint in the OnNotify? Are you getting notifications for all item selections?

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            S 1 Reply Last reply
            0
            • M Mark Salsbery

              Do you call SetCheck anywhere? How do the items get their check state set? What's happening in your SetDecendentNodes functions? Have you put a breakpoint in the OnNotify? Are you getting notifications for all item selections?

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              S Offline
              S Offline
              Stuck At Zero
              wrote on last edited by
              #9

              I do not call SetCheck. The nodes get their check state set whenever the user clicks on the node's box to check or uncheck the node.

              M 1 Reply Last reply
              0
              • S Stuck At Zero

                I do not call SetCheck. The nodes get their check state set whenever the user clicks on the node's box to check or uncheck the node.

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #10

                Ohhh.... Maybe you want the TVN_ITEMCHANGED notification instead of TVN_SELCHANGED

                BOOL CViewFilter::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
                {
                if (wParam == IDC_TREE1)
                {
                NMHDR *pHdr = (NMHDR *)lParam;

                if (pHdr->code == TVN\_ITEMCHANGED)
                {
                  NMTVITEMCHANGE \*pNMTVItemChange = (NMTVITEMCHANGE \*)lParam;
                
                  if (pNMTVItemChange->hItem)
                  {
                    if (m\_filterTreeCtrl.GetCheck(pNMTreeView->itemNew.hItem))
                    {
                      // Select All Subsequent Children Nodes
                      SetDecendentNodesOn(pNMTVItemChange->hItem);
                    }
                    else
                    {
                      // Deselect All Subsequent Children Nodes
                      SetDecendentNodesOff(pNMTVItemChange->hItem);
                    }
                  }
                
                  return TRUE;
                }
                

                }

                return CDialog::OnNotify(wParam, lParam, pResult);
                }

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                S 1 Reply Last reply
                0
                • M Mark Salsbery

                  Ohhh.... Maybe you want the TVN_ITEMCHANGED notification instead of TVN_SELCHANGED

                  BOOL CViewFilter::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
                  {
                  if (wParam == IDC_TREE1)
                  {
                  NMHDR *pHdr = (NMHDR *)lParam;

                  if (pHdr->code == TVN\_ITEMCHANGED)
                  {
                    NMTVITEMCHANGE \*pNMTVItemChange = (NMTVITEMCHANGE \*)lParam;
                  
                    if (pNMTVItemChange->hItem)
                    {
                      if (m\_filterTreeCtrl.GetCheck(pNMTreeView->itemNew.hItem))
                      {
                        // Select All Subsequent Children Nodes
                        SetDecendentNodesOn(pNMTVItemChange->hItem);
                      }
                      else
                      {
                        // Deselect All Subsequent Children Nodes
                        SetDecendentNodesOff(pNMTVItemChange->hItem);
                      }
                    }
                  
                    return TRUE;
                  }
                  

                  }

                  return CDialog::OnNotify(wParam, lParam, pResult);
                  }

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  S Offline
                  S Offline
                  Stuck At Zero
                  wrote on last edited by
                  #11

                  Yeah, that was one I had tried using before but the problem is you need Windows Vista to use it. I'm running on XP Pro.

                  M 1 Reply Last reply
                  0
                  • S Stuck At Zero

                    Yeah, that was one I had tried using before but the problem is you need Windows Vista to use it. I'm running on XP Pro.

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #12

                    Stuck At Zero wrote:

                    the problem is you need Windows Vista to use it

                    There's other OSs? Do you get any notification in XP when you check/uncheck an item? If so, what is the code? Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    S 1 Reply Last reply
                    0
                    • M Mark Salsbery

                      Stuck At Zero wrote:

                      the problem is you need Windows Vista to use it

                      There's other OSs? Do you get any notification in XP when you check/uncheck an item? If so, what is the code? Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      S Offline
                      S Offline
                      Stuck At Zero
                      wrote on last edited by
                      #13

                      I do not know how to find any other notification in XP other than what's listed in MSDN.... but the one you just recommended is here: http://msdn.microsoft.com/en-us/library/bb773526(VS.85).aspx It says the minimum operating system is Windows Vista.

                      M 1 Reply Last reply
                      0
                      • S Stuck At Zero

                        I do not know how to find any other notification in XP other than what's listed in MSDN.... but the one you just recommended is here: http://msdn.microsoft.com/en-us/library/bb773526(VS.85).aspx It says the minimum operating system is Windows Vista.

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #14

                        I really thought it was available on XP. The macro is wrapped in "#if (_WIN32_IE >= 0x0600)" which seems to indicate a common controls version 6 or better feature. If you define _WIN32_IE to something >= 0x0600 does it work on XP? I don't have a handy XP machine to test on. Also, have you tried (in the debugger)to see if there's any notification sent when you change the check state? I'm interested in what notification code it is if there is one.

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        S 1 Reply Last reply
                        0
                        • M Mark Salsbery

                          I really thought it was available on XP. The macro is wrapped in "#if (_WIN32_IE >= 0x0600)" which seems to indicate a common controls version 6 or better feature. If you define _WIN32_IE to something >= 0x0600 does it work on XP? I don't have a handy XP machine to test on. Also, have you tried (in the debugger)to see if there's any notification sent when you change the check state? I'm interested in what notification code it is if there is one.

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          S Offline
                          S Offline
                          Stuck At Zero
                          wrote on last edited by
                          #15

                          I couldn't figure out how to filter out the other things OnNotify would trigger, but I believe part of my problem seems to be that the hItem is what the TreeView has as a keyboard highlighted region rather than the actual node clicked on by mouse. Do you have any ideas as to change hItem to reflect what is actually clicked on by the mouse and thus ignore the keyboard rectangular region that highlights the 1st root node or changes if I use my keyboard to move it around? In other words,

                          HTREEITEM hItem = m_filterTreeCtrl.GetSelectedItem(); // Keyboard Highlighted Region

                          Is not with respect to the node I click on with my mouse.

                          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