?
Solved

De-select a node in TreeView

Posted on 2003-03-25
8
Medium Priority
?
756 Views
Last Modified: 2010-05-18
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
Comment
Question by:heartland
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 

Expert Comment

by:paulbates
ID: 8207155
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
 

Author Comment

by:heartland
ID: 8210892
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
 

Expert Comment

by:paulbates
ID: 8212071
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:heartland
ID: 8212553
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
 

Author Comment

by:heartland
ID: 8212559
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
 

Expert Comment

by:paulbates
ID: 8212916
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
 

Author Comment

by:heartland
ID: 8213663
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
 

Accepted Solution

by:
paulbates earned 200 total points
ID: 8213964
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question