TreeNodeExpanded

J

JollyJollyBean

Hi all,

I have a page that has a very large organizational tree, since it was
taking a while to load, I altered the tree to dynamically build itself
using the TreeNodeExpanded event. This significantly improved
performance and worked well until I noticed a strange behavior. The
tree worked exactly the same except when a node was checked. When the
user checked any node, then expanded a new node, all of the checked
nodes moved to the root level of the tree, regardless of how deep they
were in the tree. If the user then tried to un-expand a node, then the
tree would show itself as normal with the expanded node un-expanded.
If the user tried to un-expand a checked node, the tree moves the
expanded node back to where it should be, but it remains expanded. If
the user clicks the same node a third time, it un-expands at it should.

Example:

Initial tree state (ExpandDepth set to 1). When everything is
un-checked, the tree works as expected.
[-] [ ] <root>
[+] [ ] <node 1>
[+] [ ] <node 2>
[+] [ ] <node 3>

User expands node 1 while node 1 is checked. All checked items are
moved to the root level.
[-] [ ] <root>
[-] [X] <node 1>
[+] [ ] <node 1_1>
[ ] <node 2_2>
[+] [ ] <node 2>
[+] [ ] <node 3>

User tries to un-expand node 1, node 1 moves back under root node where
it belongs. Node 1 remains expanded.
[-] [ ] <root>
[-] [X] <node 1>
[+] [ ] <node 1_1>
[ ] <node 2_2>
[+] [ ] <node 2>
[+] [ ] <node 3>

User clicks to un-expand node 1 a second time, node 1 un-expands as
expected.
[-] [ ] <root>
[+] [X] <node 1>
[+] [ ] <node 2>
[+] [ ] <node 3>

Anyone seen this behavior before or have any clues?

Here is the recursive method I am using to load the tree. It is being
called by the TreeNodeExpanded event:

Private Sub loadChildren (ByVal tn As TreeNode, ByVal id As String,
ByVal dv As System.Data.DataView, ByVal levels As Int16)
If (levels = 0) Then
Exit Sub
End If
dv.RowFilter = "[parent] = " & id & " and orgId <> " & id
For Each dr As System.Data.DataRow In dv.ToTable().Rows
Dim child As New TreeNode(dr("OrgSymbol"), dr("orgId"))
child.ShowCheckBox = True
child.SelectAction = TreeNodeSelectAction.None
tn.ChildNodes.Add(child)
loadChildren(child, dr("orgId"), dv, levels - 1)
Next
End Sub

TIA,
Jolly
 
Joined
Apr 30, 2008
Messages
1
Reaction score
0
Same problem

Hi Jolly! I'm using a Treeview with same idea as your's, and getting same problem too.

If you had your problem solved, please contact me about the solution!

Thanks a lot!

Josias
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top