Using C#
I want to know if it is possible to limit the user to only being able
to see the path of the current node.
In other words I dont wan't the user to be able to see any expanded
stuff that isn't part of the path of the selected node.
So I need some kind of function that will CollapseAll() except the part
of the tree the user is currently working with...
If this is possible does anyone have any ideas to point me in the right
dirrection?
:confused:
Thanks.
windows.form.treeview control question
Started by hoser2001, Jul 11 2006 09:07 AM
11 replies to this topic
#1
Posted 11 July 2006 - 09:07 AM
|
|
|
#2
Posted 11 July 2006 - 09:24 AM
Let me see if I understand you (in ascii tree-view layout, lol):
Tree Root
- 2nd Node
-- 2nd Node, 1st Child Node
- 3rd Node
- - 3rd Node, 1st Child Node
- 4th Node
Now, you want everything non-visible except the one they are working in, such as 3rd Node, 1st Node in the tree above? So, do you want all other nodes to be Collapsed or do you want nothing to be seen except 3rd Node, 1st Node?
A) Do you want them to see just
3rd Node, First Child Node
OR
B)
Tree Root
- 2nd Node
- 3rd Node
- - 3rd Node, 1st Child Node // Working node
- 4th Node
.... I'm assuming B?
Tree Root
- 2nd Node
-- 2nd Node, 1st Child Node
- 3rd Node
- - 3rd Node, 1st Child Node
- 4th Node
Now, you want everything non-visible except the one they are working in, such as 3rd Node, 1st Node in the tree above? So, do you want all other nodes to be Collapsed or do you want nothing to be seen except 3rd Node, 1st Node?
A) Do you want them to see just
3rd Node, First Child Node
OR
B)
Tree Root
- 2nd Node
- 3rd Node
- - 3rd Node, 1st Child Node // Working node
- 4th Node
.... I'm assuming B?
#3
Posted 12 July 2006 - 02:47 AM
It looks like there's a CollapseAll method on TreeView, so my initial thought would be to hook up an event handler to the TreeView.BeforeExpand event and call TreeView.CollapseAll, and then let it expand.
#4
Posted 12 July 2006 - 04:12 AM
A) Do you want them to see just
3rd Node, First Child Node
OR
B)
Tree Root
- 2nd Node
- 3rd Node
- - 3rd Node, 1st Child Node // Working node
- 4th Node
.... I'm assuming B?[/QUOTE
Yep.
I'm thinking I need to use the depth property but I'm not sure... maybe theres another way?
3rd Node, First Child Node
OR
B)
Tree Root
- 2nd Node
- 3rd Node
- - 3rd Node, 1st Child Node // Working node
- 4th Node
.... I'm assuming B?[/QUOTE
Yep.
I'm thinking I need to use the depth property but I'm not sure... maybe theres another way?
#5
Posted 12 July 2006 - 04:22 AM
THanks guys but I figured this one out... Here's what I did.
Pretty simple actually:D
TreeNode objNode = (TreeNode)e.Node;
treeView1.CollapseAll();
if (!objNode.IsExpanded)
{
objNode.EnsureVisible();
}
Pretty simple actually:D
#6
Posted 12 July 2006 - 04:37 AM
Ahh. I was about to load up C# to figure this one out! So that code there keeps the one the user is working on expanded?
Does it collapse the one the user was working on?
Does it collapse the one the user was working on?
#7
Posted 12 July 2006 - 04:48 AM
Every time a node is selected the treeview collapses and expands only what it needs to display the node that was selected.
Now I have another problem, everytime this happens the treeview "flickers" I don't think this is acceptable, is there some way to prevent this?
Now I have another problem, everytime this happens the treeview "flickers" I don't think this is acceptable, is there some way to prevent this?
#8
Posted 12 July 2006 - 04:58 AM
Figured this one out too....
just stick a treeView1.Update(); after the if statement and the problem is solved.
just stick a treeView1.Update(); after the if statement and the problem is solved.
#9
Posted 12 July 2006 - 05:41 AM
The update will cause it not to flicker?
#10
Posted 12 July 2006 - 08:38 AM
The Update function stopped the flickering, but after testing it further it still wasn't stopping all the visual defects caused by the collapsing and expanding of nodes. So I had to revise the code a little,and this works like a charm;)
TreeNode objNode = (TreeNode)e.Node; treeView1.BeginUpdate(); treeView1.CollapseAll(); if (!objNode.IsExpanded) objNode.EnsureVisible(); treeView1.EndUpdate();
#11
Posted 12 July 2006 - 08:41 AM
and to explain, the beginupdate() function lets the program know that no visual changes should be made to the treeview until the endupdate() function is called. This prevents the treeview from showing nodes collapsing and expanding which isn't noticable if you're only dealing with a few nodes.
#12
Posted 13 July 2006 - 09:35 AM
Very nice code hoser. I never knew about the treeview update feature.


Sign In
Create Account


Back to top









