Results 1 to 6 of 6

Thread: Byval treeview modifies original

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    48

    Byval treeview modifies original

    I am working on a small project that uses the treeview control in .net 2003. I have a tree view that I am sending to a sub in order to iterate through the nodes.

    Public Sub test (ByVal inTreeView as Tree View)

    But, the thing I want to do with the inTreeView requires me to expand all the nodes before I iterate. The problem is that when the sub is complete, the original tree view on my form ends up with all of the nodes expanded I had hoped that sending it to my sub "ByVal" would make a copy that I could mess around with without effecting the original. I also tried creating a new treeview and assigning the inTreeView to it, then doing my stuff:

    dim TestTree as new TreeView
    TestTree = inTreeView

    but no matter what the source treeview always gets expanded when I do an expandall TestTree.ExpandAll()

    Can anyone tell me how to get a duplicate of a treeview in a way that I can expandall and not effect the source object?

    Thanks
    cas

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Byval treeview modifies original

    Firstly, expanding nodes in a TreeView is a visual thing. If you don't want the user to see the nodes expanded I don't see why you would need to expand them in the first place. There's nothing to stop you navigating an entire tree in code whether nodes are expanded or not. I'd be interested to know why you need, or at least think you need, to expand all the nodes.

    If it turns out that you genuinely do need to expand all the nodes then there is no way to get a copy other than to create a new TreeView object, Clone each node from the original and add it to the new tree.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    48

    Re: Byval treeview modifies original

    I am printing the nodes and using the n.Bounds.Location.X directly when printing to know how far to indent child nodes. It works great, but if a node is collapsed, the location is 0 and I have to expand them all to actually get the information for all nodes If you have an easier way to indent the nodes while printing, I am all ears...

    -cas

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Byval treeview modifies original

    You don't have to use any information from the actual UI to print the tree. I would just use the Depth property of each node to determine how many indentations to apply to each node when printing. Multiply that by the Indent property of the TreeView and that's the X coordinate of your rectangle. You can use Font.MeasurString to get a Rectangle that will bound the Text of a node in the font you want to print it in.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2002
    Posts
    48

    Re: Byval treeview modifies original

    Sorry to bother you again but I am not exactly sure where to find the "depth" property of the treenode? I did a search on google and also looked at all the properties of a tree node but didn't find the depth?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Byval treeview modifies original

    B*gger! Sorry about that. Depth is for the WebForms TreeNode class. The WinForms TreeNode has the Level property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width