TreeView.TopNode TreeView.TopNode TreeView.TopNode TreeView.TopNode Property

정의

트리 뷰 컨트롤에서 완전히 표시되는 첫 번째 트리 노드를 가져오거나 설정합니다.Gets or sets the first fully-visible tree node in the tree view control.

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

속성 값

TreeNode 트리 뷰 컨트롤에서 첫 번째 완벽 하 게 표시 되는 트리 노드를 나타내는입니다.A TreeNode that represents the first fully-visible tree node in the tree view control.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 BeforeLabelEdit AfterSelectTopNode 멤버입니다.The following code example demonstrates how to use the BeforeLabelEditAfterSelect and TopNode members. 이 예제를 실행 하려면 포함 된 폼에서 다음 코드를 붙여 넣습니다를 TreeView 라는 컨트롤을 TreeView1입니다.To run this example, paste the following code in a form that contains a TreeView control that is named TreeView1. 호출 된 InitializeTreeView 폼의 생성자 또는 Load 메서드.Call the InitializeTreeView method in the form's constructor or Load method.

private:
   void InitializeTreeView()
   {
      
      // Construct the TreeView object.
      this->TreeView1 = gcnew System::Windows::Forms::TreeView;
      
      // Set dock, location, size name, and tab order
      // values for the TreeView object.
      TreeView1->Dock = System::Windows::Forms::DockStyle::Left;
      TreeView1->Location = System::Drawing::Point( 0, 0 );
      TreeView1->Name = "TreeView1";
      TreeView1->Size = System::Drawing::Size( 152, 266 );
      TreeView1->TabIndex = 1;
      
      // Associate the event-handling methods with the
      // BeforeLabeEdit and the AfterSelect events.
      TreeView1->BeforeLabelEdit += gcnew NodeLabelEditEventHandler( this, &Form1::TreeView1_BeforeLabelEdit );
      TreeView1->AfterSelect += gcnew TreeViewEventHandler( this, &Form1::TreeView1_AfterSelect );
      
      // Set the LabelEdit property to true to allow the 
      // user to edit the TreeNode text.
      this->TreeView1->LabelEdit = true;
      
      // Declare and create objects needed to populate 
      // the TreeView.
      array<String^>^files = {"bigPresentation.ppt","myFinances.xls","myResume.doc"};
      ;
      String^ filePath = "c:\\myFiles";
      System::Collections::ArrayList^ nodes = gcnew System::Collections::ArrayList;
      
      // Create a node for each file, setting the Text property to the 
      // file's name and the Tag property to file's fully-qualified name.
      System::Collections::IEnumerator^ myEnum = files->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         String^ file = safe_cast<String^>(myEnum->Current);
         TreeNode^ node = gcnew TreeNode( file );
         node->Tag = String::Concat( filePath, "\\", file );
         nodes->Add( node );
      }

      array<TreeNode^>^treeNodes = gcnew array<TreeNode^>(nodes->Count);
      nodes->CopyTo( treeNodes );
      
      // Create a new node named topNode and add the ArrayList of 
      // nodes to topNode.
      TreeNode^ topNode = gcnew TreeNode( "myFiles",treeNodes );
      topNode->Tag = filePath;
      
      // Add topNode to the TreeView.
      TreeView1->Nodes->Add( topNode );
      
      // Add the TreeView to the form.
      this->Controls->Add( TreeView1 );
   }

   void TreeView1_BeforeLabelEdit( Object^ /*sender*/, NodeLabelEditEventArgs^ e )
   {
      
      // Determine whether the user has selected the top node. If so,
      // change the CancelEdit property to true to cancel the edit.
      if ( e->Node == TreeView1->TopNode )
      {
         e->CancelEdit = true;
         MessageBox::Show( "You are not allowed to edit the top node" );
      }

   }
private void InitializeTreeView()
{

	// Construct the TreeView object.
	this.TreeView1 = new System.Windows.Forms.TreeView();

	// Set dock, location, size name, and tab order
	// values for the TreeView object.
	TreeView1.Dock = System.Windows.Forms.DockStyle.Left;
	TreeView1.Location = new System.Drawing.Point(0, 0);
	TreeView1.Name = "TreeView1";
	TreeView1.Size = new System.Drawing.Size(152, 266);
	TreeView1.TabIndex = 1;
	
	// Associate the event-handling methods with the
	// BeforeLabeEdit and the AfterSelect events.
	TreeView1.BeforeLabelEdit += 
		new NodeLabelEditEventHandler(TreeView1_BeforeLabelEdit);
	TreeView1.AfterSelect += 
		new TreeViewEventHandler(TreeView1_AfterSelect);

	// Set the LabelEdit property to true to allow the 
	// user to edit the TreeNode text.
	this.TreeView1.LabelEdit = true;

	// Declare and create objects needed to populate 
	// the TreeView.
	string[] files = new string[]{"bigPresentation.ppt", 
		"myFinances.xls", "myResume.doc"};; 
	string filePath = "c:\\myFiles";
	System.Collections.ArrayList nodes = 
		new System.Collections.ArrayList();

	// Create a node for each file, setting the Text property to the 
	// file's name and the Tag property to file's fully-qualified name.
	foreach ( string file in files )
	{
		TreeNode node = new TreeNode(file);
		node.Tag = filePath+"\\"+file;
		nodes.Add(node);
	}

	TreeNode[] treeNodes = new TreeNode[nodes.Count];
	nodes.CopyTo(treeNodes);

	// Create a new node named topNode and add the ArrayList of 
	// nodes to topNode.
	TreeNode topNode = new TreeNode("myFiles",  treeNodes);
	topNode.Tag = filePath;

	// Add topNode to the TreeView.
	TreeView1.Nodes.Add(topNode);

	// Add the TreeView to the form.
	this.Controls.Add(TreeView1);
}

private void TreeView1_BeforeLabelEdit(object sender, 
	NodeLabelEditEventArgs e)
{

	// Determine whether the user has selected the top node. If so,
	// change the CancelEdit property to true to cancel the edit.  
	if (e.Node == TreeView1.TopNode)

	{
		e.CancelEdit = true;
		MessageBox.Show("You are not allowed to edit the top node");
	}
	
}
Private Sub InitializeTreeView()

    ' Construct the TreeView object.
    Me.TreeView1 = New System.Windows.Forms.TreeView

    ' Set dock, location, size name, and tab order
    ' values for the TreeView object.

    With TreeView1
        .Dock = System.Windows.Forms.DockStyle.Left
        .Location = New System.Drawing.Point(0, 0)
        .Name = "TreeView1"
        .Size = New System.Drawing.Size(152, 266)
        .TabIndex = 1
    End With

    ' Set the LabelEdit property to true to allow the 
    ' user to edit the TreeNode text.
    Me.TreeView1.LabelEdit = True

    ' Declare and create objects needed to populate 
    ' the TreeView.
    Dim file, files(), filePath As String
    files = New String() {"bigPresentation.ppt", "myFinances.xls", _
        "myResume.doc"}
    filePath = "c:\myFiles"
    Dim nodes As New System.Collections.ArrayList

    ' Create a node for each file, setting the Text property to the 
    ' file's name and the Tag property to file's fully-qualified name.
    For Each file In files
        Dim node As New TreeNode(file)
        node.Tag = filePath & "\" & file
        nodes.Add(node)
    Next

    ' Create a new node named topNode and add the ArrayList of 
    ' nodes to topNode.
    Dim topNode As New TreeNode("myFiles", _
        nodes.ToArray(GetType(TreeNode)))

    topNode.Tag = filePath

    ' Add topNode to the TreeView.
    TreeView1.Nodes.Add(topNode)

    ' Add the TreeView to the form.
    Me.Controls.Add(TreeView1)
End Sub

Private Sub TreeView1_BeforeLabelEdit(ByVal sender As Object, _
    ByVal e As NodeLabelEditEventArgs) Handles TreeView1.BeforeLabelEdit

    ' Determine whether the user has selected the top node. If so,
    ' change the CancelEdit property to true to cancel the edit.  
    If (e.Node Is TreeView1.TopNode) Then

        e.CancelEdit = True
        MessageBox.Show("You are not allowed to edit the top node")
    End If


End Sub
private:
   // Handle the After_Select event.
   void TreeView1_AfterSelect( System::Object^ /*sender*/, System::Windows::Forms::TreeViewEventArgs^ e )
   {
      
      // Vary the response depending on which TreeViewAction
      // triggered the event. 
      switch ( (e->Action) )
      {
         case TreeViewAction::ByKeyboard:
            MessageBox::Show( "You like the keyboard!" );
            break;

         case TreeViewAction::ByMouse:
            MessageBox::Show( "You like the mouse!" );
            break;
      }
   }
// Handle the After_Select event.
private void TreeView1_AfterSelect(System.Object sender, 
	System.Windows.Forms.TreeViewEventArgs e)
{

	// Vary the response depending on which TreeViewAction
	// triggered the event. 
	switch((e.Action))
	{
		case TreeViewAction.ByKeyboard:
			MessageBox.Show("You like the keyboard!");
			break;
		case TreeViewAction.ByMouse:
			MessageBox.Show("You like the mouse!");
			break;
	}
}
' Handle the After_Select event.
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.TreeViewEventArgs) _
        Handles TreeView1.AfterSelect

    ' Vary the response depending on which TreeViewAction
    ' triggered the event. 
    Select Case (e.Action)
        Case TreeViewAction.ByKeyboard
            MessageBox.Show("You like the keyboard!")
        Case TreeViewAction.ByMouse
            MessageBox.Show("You like the mouse!")
    End Select
End Sub

설명

처음에 TopNode 위쪽에 있는 첫 번째 루트 트리 노드를 반환 합니다 TreeView합니다.Initially, the TopNode returns the first root tree node, which is located at the top of the TreeView. 그러나 사용자 콘텐츠를 스크롤 하는 경우 다른 트리 노드 맨 위에 있는 수 있습니다.However, if the user has scrolled the contents, another tree node might be at the top.

참고

가 없으면이이 속성을 설정 하면 적용 된 Scrollable 속성 값이 false합니다.Setting this property has no effect when the Scrollable property value is false.

적용 대상

추가 정보