I using TreeView with ShowCheckBoxes="All" in an ASP.NET 3.5 web application and for some reason the checked nodes are not returned in order. Lets say I have nodes A,B,C and I select B and C and hit the save button and when I check the CheckedNodes property of the Treeview the checked nodes are in order (B,C). But the next time when I go back to the page and select the node A the order is being returned B,C,A. What could be the reason for this behavior?
+1
A:
CheckedNodes is a TreeNodeCollection which just implements ICollection. When the checkChanged event fires, it probably just adds the tree nodes to the CheckedNodes collection.
Nothing I can see on MSDN implies that you should assume the nodes would be ordered. All it says is:
Each time the page is posted to the server, the CheckedNodes collection is automatically populated with the selected nodes.
From your experiment, it seems safe to assume that on the second postback, it simply adds any new checked nodes to the collection, rather than clearing the collection and re-adding everything.
womp
2010-01-03 20:51:39