TreeView.SelectedNode 속성

정의

tree view 컨트롤에 현재 선택되어 있는 트리 노드를 가져오거나 설정합니다.

public:
 property System::Windows::Forms::TreeNode ^ SelectedNode { System::Windows::Forms::TreeNode ^ get(); void set(System::Windows::Forms::TreeNode ^ value); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.TreeNode SelectedNode { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectedNode : System.Windows.Forms.TreeNode with get, set
Public Property SelectedNode As TreeNode

속성 값

TreeNode

tree view 컨트롤에 현재 선택되어 있는 TreeNode입니다.

특성

예제

다음 코드 예제에서는 a TreeView 의 속성을 설정 PathSeparator 하 고에 포함 된 TreeNodeCollection 자식 트리 노드의 SelectedNode수를 표시 합니다. 트리 뷰 컨트롤의 총 트리 노드에 대한 자식 트리 노드의 백분율도 표시됩니다. 이 예제에서는 여러 TreeNode 개체가 있는 컨트롤(TreeView가급적이면 3개 이상의 수준 포함)을 가진 컨트롤 TreeNodeCollection 이 있어야 Form Button합니다.

void myButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{

   // Set the tree view's PathSeparator property.
   myTreeView->PathSeparator = ".";

   // Get the count of the child tree nodes contained in the SelectedNode.
   int myNodeCount = myTreeView->SelectedNode->GetNodeCount( true );
   Decimal myChildPercentage = ((Decimal)myNodeCount / (Decimal)myTreeView->GetNodeCount( true )) * 100;

   // Display the tree node path and the number of child nodes it and the tree view have.
   MessageBox::Show( String::Concat( "The '", myTreeView->SelectedNode->FullPath, "' node has ", myNodeCount, " child nodes.\nThat is ", String::Format( "{0:###.##}", myChildPercentage ), "% of the total tree nodes in the tree view control." ) );
}
private void myButton_Click(object sender, System.EventArgs e)
{
   // Set the tree view's PathSeparator property.
   myTreeView.PathSeparator = ".";

   // Get the count of the child tree nodes contained in the SelectedNode.
   int myNodeCount = myTreeView.SelectedNode.GetNodeCount(true);
   decimal myChildPercentage = ((decimal)myNodeCount/
     (decimal)myTreeView.GetNodeCount(true)) * 100;

   // Display the tree node path and the number of child nodes it and the tree view have.
   MessageBox.Show("The '" + myTreeView.SelectedNode.FullPath + "' node has "
     + myNodeCount.ToString() + " child nodes.\nThat is "
     + string.Format("{0:###.##}", myChildPercentage)
     + "% of the total tree nodes in the tree view control.");
}
Private Sub myButton_Click(ByVal sender As Object, _
  ByVal e As System.EventArgs) Handles myButton.Click
   ' Set the tree view's PathSeparator property.
   myTreeView.PathSeparator = "."

   ' Get the count of the child tree nodes contained in the SelectedNode.
   Dim myNodeCount As Integer = myTreeView.SelectedNode.GetNodeCount(True)
   Dim myChildPercentage As Decimal = CDec(myNodeCount) / _
      CDec(myTreeView.GetNodeCount(True)) * 100

   ' Display the tree node path and the number of child nodes it and the tree view have.
   MessageBox.Show(("The '" + myTreeView.SelectedNode.FullPath + "' node has " _
      + myNodeCount.ToString() + " child nodes." + Microsoft.VisualBasic.ControlChars.Lf _
      + "That is " + String.Format("{0:###.##}", myChildPercentage) _
      + "% of the total tree nodes in the tree view control."))
End Sub

설명

현재 선택되어 있지 TreeNode 않으면 속성은 SelectedNode .입니다 null.

이 속성을 설정하면 지정된 노드가 보기로 스크롤되고 부모 노드가 확장되어 지정된 노드가 표시됩니다.

선택한 노드의 부모 노드 또는 상위 노드가 프로그래밍 방식으로 또는 사용자 작업을 통해 축소되면 축소된 노드는 선택한 노드가 됩니다.

적용 대상

추가 정보