Treeview control problem: Selected node is not retained when parent node is closed.
I have a treeView control on the top half of a Windows form. When you select a node in the tree, the bottom half of the form displays the associated data for the selected node.
My problem is that if the user closes the node, the selection is moved to the parent node and not retained. If the user then opens the parent node again - the selection is no longer there.
Is there a way to prevent this behavior and have the system retain the selected node?
Thanks!
[484 byte] By [
DeborahK] at [2007-12-23]
Do you always want to restrict user selection?
You can use the ensurevisible and the expand methods to show the children of the selected node. You can also create a node object that is checked during the node selected event if it is a parent of what is being selected and react accordingly
HTH
I don't want to ever restrict user selection.
Let me try explaining this again...
I have a TreeView control that has nodes and subnodes. The node or subnode that the user picks at the top of the form defines what is displayed at the bottom of the form.
Here is an example treeview:
Clients
- Active Clients
-- Microsoft
-- Apple
If the user clicks on Apple, the information regarding Apple is displayed in the bottom. If the user clicks on Active Clients, information about all Active Clients is displayed in the bottom.
If the user clicks on Apple and THEN closes the Active Clients node. It appears that the treeview then automatically selects the Active Clients node without generating the selected events, so the bottom portion of the screen still has info about Apple but it appears on the top that they have Active Clients selected. This is confusing for the users.
If the user then re-opens Active Clients, Apple is no longer selected - even though the data for it appears in the bottom part of the screen.
I would have expected that if I closed and then reopened ActiveClients that Apple would have remained selected.