Recreate a >>C# WinForms<< TreeView "state" -after- treeview rebuild ?? Any TreeView GODS out there ??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frostbb

    Recreate a >>C# WinForms<< TreeView "state" -after- treeview rebuild ?? Any TreeView GODS out there ??

    I have a C# WinForms treeview with 20 or so 'level 0' nodes.

    My users will normally have 2 of the 'level 0' branches open down to a '5th
    level' selected node.

    The users will make updates to the 2 selected nodes that will alter the node
    name.

    I think I need to rebuild the TreeView to get everything synchronized after
    they click an update button.

    Is there an example somewhere that shows how to recreate and re-expand level
    0 branches of the TreeView state after the Tree has been rebuilt?

    Put another way ... At the time the user commits an update the Level 0 nodes
    5 and 18 are open 'down' to a pair of selected 5th level nodes. One node per
    branch. All the other level 0 nodes are collapsed.

    How do I rebuild the treeview and open the 5 and 18 level 0 nodes down to
    the 5th level and reselect the 5th level nodes that the users had
    previously selected and updated ?? I can save the names of the previously
    selected and updated nodes. I'm just unsure of how to selectively expand
    the 5 and 18 level 0 branches down to the 5th level and reselect the target
    nodes.

    Any help would be GREATLY appreciated.

    Thanks in advance.

    Barry in Oregon



  • Joel Lucsy

    #2
    Re: Recreate a &gt;&gt;C# WinForms&lt;&lt ; TreeView &quot;state&quo t; -after- treeviewrebuild ?? Any TreeView GODS out there ??

    frostbb wrote:
    How do I rebuild the treeview and open the 5 and 18 level 0 nodes down to
    the 5th level and reselect the 5th level nodes that the users had
    previously selected and updated ?? I can save the names of the previously
    selected and updated nodes. I'm just unsure of how to selectively expand
    the 5 and 18 level 0 branches down to the 5th level and reselect the target
    nodes.
    Save the state of ANY node that is expanded. When rebuilding the tree,
    after inserting a node and inserting its children, check to see if its
    one of your saved expanded nodes, and expand it.
    For storing which items are expanded, I'd store the full path to the
    node from the root.

    --
    Joel Lucsy
    "The dinosaurs became extinct because they didn't have a space program."
    -- Larry Niven

    Comment

    • Pavel Minaev

      #3
      Re: Recreate a &gt;&gt;C# WinForms&lt;&lt ; TreeView &quot;state&quo t; -after- treeviewrebuild ?? Any TreeView GODS out there ??


      frostbb wrote:
      I have a C# WinForms treeview with 20 or so 'level 0' nodes.
      >
      My users will normally have 2 of the 'level 0' branches open down to a '5th
      level' selected node.
      >
      The users will make updates to the 2 selected nodes that will alter the node
      name.
      >
      I think I need to rebuild the TreeView to get everything synchronized after
      they click an update button.
      Not necessarily. If you can track the specific changes that are
      happening to the data source from which the tree is loaded, you can
      avoid the full rebuild, instead just inserting, removing or moving the
      nodes that were changed. And that will preserve the collapsed/expanded
      state of all nodes.

      Comment

      • frostbb

        #4
        Re: Recreate a &gt;&gt;C# WinForms&lt;&lt ; TreeView &quot;state&quo t; -after- treeview rebuild ?? Any TreeView GODS out there ??

        Thanks for the reply. Hadn't considered simply dropping and recreating the
        existing nodes. In this case I may actully be able to get away with that!
        I'm pretty sure I can get this thing to work using your and the other
        replies to my question.

        Best wishes. Happy computing and THANKS!

        Barry in Oregon

        "Pavel Minaev" <int19h@gmail.c omwrote in message
        news:9c5b9387-680b-48db-933a-e795a5bfa6a9@f3 6g2000hsa.googl egroups.com...
        >
        frostbb wrote:
        >I have a C# WinForms treeview with 20 or so 'level 0' nodes.
        >>
        >My users will normally have 2 of the 'level 0' branches open down to a
        >'5th
        >level' selected node.
        >>
        >The users will make updates to the 2 selected nodes that will alter the
        >node
        >name.
        >>
        >I think I need to rebuild the TreeView to get everything synchronized
        >after
        >they click an update button.
        >
        Not necessarily. If you can track the specific changes that are
        happening to the data source from which the tree is loaded, you can
        avoid the full rebuild, instead just inserting, removing or moving the
        nodes that were changed. And that will preserve the collapsed/expanded
        state of all nodes.

        Comment

        • frostbb

          #5
          Re: Recreate a &gt;&gt;C# WinForms&lt;&lt ; TreeView &quot;state&quo t; -after- treeview rebuild ?? Any TreeView GODS out there ??

          Joel,

          Thanks for the reply. Really appreciate your time and knowledge. I'm pretty
          sure I can get this to work using your
          and the other replies to my question.

          Best wishes. Happy computing and THANKS!

          Barry in Oregon


          "Joel Lucsy" <jjlucsy@gmail. comwrote in message
          news:ObKGXwo$IH A.5956@TK2MSFTN GP04.phx.gbl...
          frostbb wrote:
          >How do I rebuild the treeview and open the 5 and 18 level 0 nodes down to
          >the 5th level and reselect the 5th level nodes that the users had
          >previously selected and updated ?? I can save the names of the
          >previously selected and updated nodes. I'm just unsure of how to
          >selectively expand the 5 and 18 level 0 branches down to the 5th level
          >and reselect the target nodes.
          >
          Save the state of ANY node that is expanded. When rebuilding the tree,
          after inserting a node and inserting its children, check to see if its one
          of your saved expanded nodes, and expand it.
          For storing which items are expanded, I'd store the full path to the node
          from the root.
          >
          --
          Joel Lucsy
          "The dinosaurs became extinct because they didn't have a space
          program." -- Larry Niven

          Comment

          Working...