Export (0) Print
Expand All

TreeNode.PrevNode Property

Gets the previous sibling tree node.

[Visual Basic]
Public ReadOnly Property PrevNode As TreeNode
[C#]
public TreeNode PrevNode {get;}
[C++]
public: __property TreeNode* get_PrevNode();
[JScript]
public function get PrevNode() : TreeNode;

Property Value

A TreeNode that represents the previous sibling tree node.

Remarks

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 a null reference (Nothing in Visual Basic).

Example

[Visual Basic, C#, C++] The following example selects the appropriate TreeNode after determining if the TreeNode passed in is selected and which TreeNode to select. This example assumes that you have a Form with a TreeView control that has a TreeNodeCollection containing several TreeNode objects. It is also assumed that you have a ComboBox with the following items: "Previous", "PreviousVisible", "Next", "NextVisible", "First", and "Last".

[Visual Basic] 
Private Sub SelectNode(node As TreeNode)
   If node.IsSelected Then
      ' Determine which TreeNode to select.
      Select Case myComboBox.Text
         Case "Previous"
            node.TreeView.SelectedNode = node.PrevNode
         Case "PreviousVisible"
            node.TreeView.SelectedNode = node.PrevVisibleNode
         Case "Next"
            node.TreeView.SelectedNode = node.NextNode
         Case "NextVisible"
            node.TreeView.SelectedNode = node.NextVisibleNode
         Case "First"
            node.TreeView.SelectedNode = node.FirstNode
         Case "Last"
            node.TreeView.SelectedNode = node.LastNode
      End Select
   End If
   node.TreeView.Focus()
End Sub

[C#] 
private void SelectNode(TreeNode node)
{
    if(node.IsSelected)
    {
        // Determine which TreeNode to select.
        switch(myComboBox.Text)
        {
            case "Previous":
                node.TreeView.SelectedNode = node.PrevNode;
                break;
            case "PreviousVisible":
                node.TreeView.SelectedNode = node.PrevVisibleNode;
                break;
            case "Next":
                node.TreeView.SelectedNode = node.NextNode;
                break;
            case "NextVisible":
                node.TreeView.SelectedNode = node.NextVisibleNode;
                break;
            case "First":
                node.TreeView.SelectedNode = node.FirstNode;
                break;
            case "Last":
                node.TreeView.SelectedNode = node.LastNode;
                break;
        }
    }
    node.TreeView.Focus();
}

[C++] 
void SelectNode(TreeNode* node) {
    if (node->IsSelected) {
        // Determine which TreeNode to select.

        String* str = myComboBox->Text;
        if (str->Equals(S"Previous"))
            node->TreeView->SelectedNode = node->PrevNode;
        else if (str->Equals(S"PreviousVisible"))
            node->TreeView->SelectedNode = node->PrevVisibleNode;
        else if (str->Equals(S"Next"))
            node->TreeView->SelectedNode = node->NextNode;
        else if (str->Equals(S"NextVisible"))
            node->TreeView->SelectedNode = node->NextVisibleNode;
        else if (str->Equals(S"First"))
            node->TreeView->SelectedNode = node->FirstNode;
        else if (str->Equals(S"Last"))
            node->TreeView->SelectedNode = node->LastNode;
    }
    node->TreeView->Focus();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

TreeNode Class | TreeNode Members | System.Windows.Forms Namespace | NextNode | LastNode | FirstNode

Show:
© 2014 Microsoft