Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 764
  • Last Modified:

De-select a node in TreeView

Hi,

How to de-select a node in TreeView? De-selected node is still being displayed as SelectedNode. For example, there are three nodes in TreeView1: Node1, Node2 and Node3 and selectedNode is Node1.  I can de-select Node1 by clicking another control on front panel. However, TreeView1.selectedNode.text is still "Node1" instead of a empty string.  How do I "Update" node-selection status?

Thanks.

Hugh
0
heartland
Asked:
heartland
  • 4
  • 4
1 Solution
 
paulbatesCommented:
You can deselect any node in the tree view control by setting 'tvCtl.SelectedNode' to 'null'. Just remember that you will not be able to retrieve the Text property as there will no longer be an object to call upon.

Doing this will also update the tree view controls view.

Paul
0
 
heartlandAuthor Commented:
Paul,

Thanks for your help. I do not quite understand.  How do I set TreeView.selectednode to "Null"?  Node1 is de-selected by mouse clicking, but TreeView.selectedNode.text still show Node1. I thought it should be a empoty string since there is no node selected.

Thanks.

Hugh
0
 
paulbatesCommented:
Hugh,

Sorry i misread your post. To answer your question can you tell me where the mouse click is; outside of the treeview control, another node or on the control but not on any node?

Paul

0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
heartlandAuthor Commented:
Paul,

Outside of the treeview control. If another node (say node2) is clicked, the TreeView.SelectedNode.text will be "Node2", which is understood.  If mouse is clicked outside of the treeview, no node is being selected, however, TreeView.SelectedNode.text still show previous selectedNode.  Thanks again.

Hugh
0
 
heartlandAuthor Commented:
Paul,

Outside of the treeview control. If another node (say node2) is clicked, the TreeView.SelectedNode.text will be "Node2", which is understood.  If mouse is clicked outside of the treeview, no node is being selected, however, TreeView.SelectedNode.text still show previous selectedNode.  Thanks again.

Hugh
0
 
paulbatesCommented:
Ok now I understand. There is two solutions depending on what you really want to do.

A. Set the tree view control's HideSelection property to false. This will then always show the selected node even when the tree view loses focus.

B. Add a LostFocus event handler to the tree view control. The event handler can then set the tree view's SelectedNode property to null.

I am assuming that your refer to 'outside' as outside the context of the entire tree view control.

Hope this helps
Paul
0
 
heartlandAuthor Commented:
Paul,

Today maybe not my day. I could not make either method working.

A. TreeView.selectedNode.text is still previously selectedNode after the treeView lost focus (by clicking another control).

B. TreeView does not have "LostFocus" event associated.

What I want is to know programatically if a node is being deselected after the TreeView lost focus.
Thanks.

Hugh
0
 
paulbatesCommented:
Hugh.

In answer to your question. No a node does not get deselected if a tree view control loses focus. A node may appear to become deselected if 'tcCtl.HideSelection == true;'. Setting the property to false will ensure that the user will always see the last selected node if the tree view has focus or not.

As for the LostFocus event, it does exist. It is inherited from Control. You could alternativly override OnLostFocus from Control instead of adding your own additional event handler method.

Paul
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now