TreeNode.Expand TreeNode.Expand TreeNode.Expand TreeNode.Expand Method

定義

展開樹狀節點。Expands the tree node.

public:
 void Expand();
public void Expand ();
member this.Expand : unit -> unit
Public Sub Expand ()

範例

下列程式碼範例會在按一下按鈕時,切換選取的節點。The following code example toggles the selected node when a button is clicked. 如果選取的節點已折迭,則會展開,如果它是藉由呼叫Expand方法來擴充,則會藉由Collapse呼叫方法來折迭。If the selected node is collapsed, it is expanded, if it is expanded by calling the Expand method, it is collapsed by calling the Collapse method. 這個Form範例需要TreeView有一個具有至少一個TreeNode具有至少一個子TreeNode系之控制項的。This example requires that you have a Form with a TreeView control that has at least one TreeNode with at least one child TreeNode.

void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if ( treeView1->SelectedNode->IsExpanded )
   {
      treeView1->SelectedNode->Collapse();
      MessageBox::Show( String::Concat( treeView1->SelectedNode->Text, " tree node collapsed." ) );
   }
   else
   {
      treeView1->SelectedNode->Expand();
      MessageBox::Show( String::Concat( treeView1->SelectedNode->Text, " tree node expanded." ) );
   }
}
private void button1_Click(object sender, System.EventArgs e)
{
   if (treeView1.SelectedNode.IsExpanded)
   {
      treeView1.SelectedNode.Collapse();
      MessageBox.Show(treeView1.SelectedNode.Text + 
        " tree node collapsed.");
   }
   else
   {
      treeView1.SelectedNode.Expand();
      MessageBox.Show(treeView1.SelectedNode.Text + 
        " tree node expanded.");
   }
}
Private Sub button1_Click(sender As Object, _
  e As System.EventArgs) Handles button1.Click
   If treeView1.SelectedNode.IsExpanded Then
      treeView1.SelectedNode.Collapse()
      MessageBox.Show(treeView1.SelectedNode.Text & _ 
        " tree node collapsed.")
   Else
      treeView1.SelectedNode.Expand()
      MessageBox.Show(treeView1.SelectedNode.Text & _
        " tree node expanded.")
   End If
End Sub 

備註

方法會將目前TreeNode的向下擴充到節點的下一個層級。 ExpandThe Expand method expands the current TreeNode down to the next level of nodes.

注意

的狀態TreeNode會保存。The state of a TreeNode is persisted. 例如,如果先前未折迭子節點的下一個層級,則在Expand呼叫方法時,子節點會出現在先前展開的狀態中。For example, if the next level of child nodes was not collapsed previously, when the Expand method is called, the child nodes appear in their previously expanded state.

適用於

另請參閱