共用方式為


TreeNode.PrevNode 屬性

定義

取得上一個同層級樹狀節點。

public:
 property System::Windows::Forms::TreeNode ^ PrevNode { System::Windows::Forms::TreeNode ^ get(); };
public System.Windows.Forms.TreeNode PrevNode { get; }
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.TreeNode PrevNode { get; }
member this.PrevNode : System.Windows.Forms.TreeNode
[<System.ComponentModel.Browsable(false)>]
member this.PrevNode : System.Windows.Forms.TreeNode
Public ReadOnly Property PrevNode As TreeNode

屬性值

TreeNode

TreeNode,表示上一個同層級樹狀節點。

屬性

範例

下列程式碼範例會在判斷 TreeNode 是否已選取傳入的專案以及要選取的專案 TreeNode 之後,選取適當的 TreeNode 。 此範例會要求您具有 Form 包含數 TreeNodeTreeView 物件的 控制項 TreeNodeCollection 。 您也需要具有 ComboBox 下列專案的 :「Previous」、「PreviousVisible」、「Next」、「NextVisible」、「First」 和 「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();
}
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();
}
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

備註

PrevNode是儲存在 Nodes TreeNodeCollection 樹狀節點父 TreeNode 系 之 屬性中的上一個同層級 TreeNode 。 如果沒有先前的樹狀節點,屬性會 PrevNodenull 回 。

適用於

另請參閱