|
-
Mar 18th, 2007, 09:42 AM
#1
Thread Starter
Member
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
-
Mar 18th, 2007, 05:27 PM
#2
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.
-
Mar 18th, 2007, 08:50 PM
#3
Thread Starter
Member
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
-
Mar 18th, 2007, 09:10 PM
#4
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.
-
Mar 19th, 2007, 06:39 PM
#5
Thread Starter
Member
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?
-
Mar 20th, 2007, 03:55 AM
#6
Re: Byval treeview modifies original
B*gger! Sorry about that. Depth is for the WebForms TreeNode class. The WinForms TreeNode has the Level property.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|