TreeNode.Remove Metoda

Definicja

Usuwa bieżący węzeł drzewa z kontrolki widoku drzewa.

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

Przykłady

Poniższy przykład kodu usuwa element TreeNode po kliknięciu prawym przyciskiem myszy myszy nad nim i przełączeniu go z rozwiniętego do zwiniętego, gdy użytkownik kliknie nad nim koło myszy. W tym przykładzie wymagane jest posiadanie Form kontrolki z kontrolką TreeView . Obiekt TreeView powinien mieć co najmniej dwa węzły drzewa głównego, z których każdy ma co najmniej jeden węzeł podrzędny.

private:
   void treeView1_MouseDown( Object^ /*sender*/, MouseEventArgs^ e )
   {
      switch ( e->Button )
      {
         // Remove the TreeNode under the mouse cursor
         // if the right mouse button was clicked.
         case ::MouseButtons::Right:
            treeView1->GetNodeAt( e->X, e->Y )->Remove();
            break;

         // Toggle the TreeNode under the mouse cursor
         // if the middle mouse button (mouse wheel) was clicked.
         case ::MouseButtons::Middle:
            treeView1->GetNodeAt( e->X, e->Y )->Toggle();
            break;
      }
   }
private void treeView1_MouseDown(object sender, MouseEventArgs e)
{
   switch(e.Button)
   {
      // Remove the TreeNode under the mouse cursor 
      // if the right mouse button was clicked. 
      case MouseButtons.Right:
         treeView1.GetNodeAt(e.X, e.Y).Remove();
         break;
      
      // Toggle the TreeNode under the mouse cursor 
      // if the middle mouse button (mouse wheel) was clicked. 
      case MouseButtons.Middle:
         treeView1.GetNodeAt(e.X, e.Y).Toggle();
         break;
   }
}
Private Sub treeView1_MouseDown(sender As Object, _
  e As MouseEventArgs) Handles treeView1.MouseDown
   Select Case e.Button
      ' Remove the TreeNode under the mouse cursor 
      ' if the right mouse button was clicked. 
      Case MouseButtons.Right
         treeView1.GetNodeAt(e.X, e.Y).Remove()
      
      ' Toggle the TreeNode under the mouse cursor 
      ' if the middle mouse button (mouse wheel) was clicked. 
      Case MouseButtons.Middle
         treeView1.GetNodeAt(e.X, e.Y).Toggle()
   End Select
End Sub

Uwagi

Po wywołaniu Remove metody węzeł drzewa i wszystkie węzły drzewa podrzędnego przypisane do TreeNodemetody są usuwane z elementu TreeView. Usunięte węzły podrzędne są usuwane z węzła, TreeView ale nadal są dołączone do tego węzła drzewa.

Dotyczy

Zobacz też