System.Web.UI.WebControls Namespace TreeView Class
.NET Framework version 2.0
Returns a TreeNode object that represents the selected node in a TreeView control.
Script |
[ TreeNode node = ] TreeView.SelectedNode |
This property can only be used programmatically; it cannot be set when declaring the control.
node |
A TreeNode object that represents the selected node in a TreeView control. |
The property is read only with no default value.
Use the SelectedNode property to determine which node is selected in a TreeView control.
The text of a node in a TreeView control can be in one of two modes: selection mode and navigation mode. A node is in navigation mode when the NavigateUrl property for the node is set to a value other than an empty string. Otherwise, the node is in selection mode, wherein the user can select a node by clicking on the node text.
NOTE: When a node is in navigation mode, the SelectedNode property returns a null reference ( Nothing in Visual Basic ).
When the user selects a different node in the TreeView control, the SelectedNodeChanged event is raised by default. The TreeView supports specifying a different event to be raised, based on the setting of the SelectAction property. The following table lists the available options.
NOTE: The HoverNodeStyle is not rendered for a node with its SelectAction property set to None.
The following example demonstrates how to use the SelectedNode property to determine which node is selected in a TreeView control.
TreeNode selectedNode = myTreeView.SelectedNode;
message.Text = "Selected TreeNode Value: " + selectedNode.Value;
Dim selectedNode As TreeNode = myTreeView.SelectedNode
message.Text = "Selected TreeNode ValuePath: " + selectedNode.Value |
|
C# |
VB |
Show me
TreeView Members SelectedValue Text Value