asp.net.ph

TreeView.SelectedNode Property

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.

Syntax


Script [ TreeNode node = ] TreeView.SelectedNode

This property can only be used programmatically; it cannot be set when declaring the control.

Property Value


node A TreeNode object that represents the selected node in a TreeView control.

The property is read only with no default value.

Remarks

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.

Selection Action Description
Expand Toggles the node between expanded and collapsed. Raises the TreeNodeExpanded or TreeNodeCollapsed event, as appropriate.
None Raises no events when a node is selected.
Select Raises the SelectedNodeChanged event when a node is selected.
SelectExpand Raises both the SelectedNodeChanged and TreeNodeExpanded events when a node is selected. Nodes are only expanded, never collapsed.

NOTE: The HoverNodeStyle is not rendered for a node with its SelectAction property set to None.

Example

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;
  C# VB

 Show me 

See Also

TreeView Members   SelectedValue   Text   Value Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph