TreeNode::PrevNode Property

 

Gets the previous sibling tree node.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
[BrowsableAttribute(false)]
property TreeNode^ PrevNode {
	TreeNode^ get();
}

Property Value

Type: System.Windows.Forms::TreeNode^

A TreeNode that represents the previous sibling tree node.

The PrevNode is the previous sibling TreeNode in the TreeNodeCollection stored in the Nodes property of the tree node's parent TreeNode. If there is no previous tree node, the PrevNode property returns null.

The following code example selects the appropriate TreeNode after determining if the TreeNode passed in is selected and which TreeNode to select. This example requires that you have a Form with a TreeView control that has a TreeNodeCollection that contains several TreeNode objects. It also requires that you have a ComboBox with the following items: "Previous", "PreviousVisible", "Next", "NextVisible", "First", and "Last".

void SelectNode( TreeNode^ node )
{
   if ( node->IsSelected )
   {

      // Determine which TreeNode to select.
      String^ str = myComboBox->Text;
      if ( str->Equals( "Previous" ) )
               node->TreeView->SelectedNode = node->PrevNode;
      else
      if ( str->Equals( "PreviousVisible" ) )
               node->TreeView->SelectedNode = node->PrevVisibleNode;
      else
      if ( str->Equals( "Next" ) )
               node->TreeView->SelectedNode = node->NextNode;
      else
      if ( str->Equals( "NextVisible" ) )
               node->TreeView->SelectedNode = node->NextVisibleNode;
      else
      if ( str->Equals( "First" ) )
               node->TreeView->SelectedNode = node->FirstNode;
      else
      if ( str->Equals( "Last" ) )
               node->TreeView->SelectedNode = node->LastNode;
   }

   node->TreeView->Focus();
}

.NET Framework
Available since 1.1
Return to top
Show: