VB.Net by API/System.Windows.Forms/TreeView — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:51, 26 мая 2010

Inherits TreeView

  
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ruponentModel
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1
        Application.Run(form1)

    End Sub
End Class


Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Private components As System.ruponentModel.IContainer
    Friend WithEvents tree As JobTree
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ruponents = New System.ruponentModel.Container()
        Me.tree = New JobTree()
        Me.SuspendLayout()
        "
        "tree
        "
        Me.tree.Location = New System.Drawing.Point(8, 8)
        Me.tree.Name = "tree"
        Me.tree.Scrollable = False
        Me.tree.Size = New System.Drawing.Size(368, 288)
        Me.tree.TabIndex = 0
        "
        "CustomJobUserTree
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(384, 310)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.tree})
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "CustomJobUserTree"
        Me.Text = "JobUser Tree"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub CustomJobUserTree_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
   
        tree.AddJob("Job 1", JobTree.StatusType.InProgress)
        tree.AddJob("Job 2", JobTree.StatusType.Unassigned)
        tree.AddJob("Job 3", JobTree.StatusType.Unassigned)
        tree.AddJob("Job 4", JobTree.StatusType.Closed)
        tree.AddJob("Job 5", JobTree.StatusType.Closed)

    End Sub
 
End Class
Public Class JobTree
    Inherits TreeView
    Public Enum StatusType
        Unassigned = 101
        InProgress = 102
        Closed = 103
    End Enum
    Private nodeUnassigned As New TreeNode("Unassigned", 0, 0)
    Private nodeInProgress As New TreeNode("In Progress", 1, 1)
    Private nodeClosed As New TreeNode("Closed", 2, 2)
    Public Sub New()
        MyBase.New()
        MyBase.Nodes.Clear()
        If Me.DesignMode = False Then
            MyBase.Nodes.Add(nodeUnassigned)
            MyBase.Nodes.Add(nodeInProgress)
            MyBase.Nodes.Add(nodeClosed)
        End If
    End Sub
    Public Sub AddJob(ByVal name As String, ByVal status As StatusType)
        Dim nodeNew As New TreeNode(name, 3, 4)
        nodeNew.Tag = status
        Select Case status
            Case StatusType.Unassigned
                nodeUnassigned.Nodes.Add(nodeNew)
            Case StatusType.InProgress
                nodeInProgress.Nodes.Add(nodeNew)
            Case StatusType.Closed
                nodeClosed.Nodes.Add(nodeNew)
        End Select
    End Sub
End Class


TreeView.AfterSelect

  
Imports System
Imports System.Collections
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ruponentModel
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1
        Application.Run(form1)

    End Sub
End Class


Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents treeFood As System.Windows.Forms.TreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.treeFood = New System.Windows.Forms.TreeView()
        Me.SuspendLayout()
        "
        "treeFood
        "
        Me.treeFood.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right)
        Me.treeFood.ImageIndex = -1
        Me.treeFood.Location = New System.Drawing.Point(4, 4)
        Me.treeFood.Name = "treeFood"
        Me.treeFood.SelectedImageIndex = -1
        Me.treeFood.Size = New System.Drawing.Size(284, 256)
        Me.treeFood.TabIndex = 0
        "
        "TreeViewExample
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.treeFood})
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "TreeViewExample"
        Me.Text = "TreeView Example"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub TreeViewExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim node As TreeNode
        node = treeFood.Nodes.Add("Node")
        node.Nodes.Add("Leap 1")
        node.Nodes.Add("Leap 2")
        node = treeFood.Nodes.Add("Node 2")
        node.Nodes.Add("Leap 3")
        node.Nodes.Add("Leap 4")
    End Sub
    Private Sub treeFood_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeFood.AfterSelect
        If e.Action = TreeViewAction.ByMouse Then
            MessageBox.Show(e.Node.FullPath)
        End If
    End Sub
End Class


TreeView.AllowDrop

  
Imports System
Imports System.Collections
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ruponentModel
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1
        Application.Run(form1)

    End Sub
End Class


Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents treeOne As System.Windows.Forms.TreeView
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents treeTwo As System.Windows.Forms.TreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.treeOne = New System.Windows.Forms.TreeView()
        Me.Splitter1 = New System.Windows.Forms.Splitter()
        Me.treeTwo = New System.Windows.Forms.TreeView()
        Me.SuspendLayout()
        "
        "treeOne
        "
        Me.treeOne.Dock = System.Windows.Forms.DockStyle.Left
        Me.treeOne.HideSelection = False
        Me.treeOne.ImageIndex = -1
        Me.treeOne.Location = New System.Drawing.Point(5, 5)
        Me.treeOne.Name = "treeOne"
        Me.treeOne.SelectedImageIndex = -1
        Me.treeOne.Size = New System.Drawing.Size(236, 351)
        Me.treeOne.TabIndex = 0
        "
        "Splitter1
        "
        Me.Splitter1.Location = New System.Drawing.Point(241, 5)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 351)
        Me.Splitter1.TabIndex = 2
        Me.Splitter1.TabStop = False
        "
        "treeTwo
        "
        Me.treeTwo.Dock = System.Windows.Forms.DockStyle.Fill
        Me.treeTwo.HideSelection = False
        Me.treeTwo.ImageIndex = -1
        Me.treeTwo.Location = New System.Drawing.Point(244, 5)
        Me.treeTwo.Name = "treeTwo"
        Me.treeTwo.SelectedImageIndex = -1
        Me.treeTwo.Size = New System.Drawing.Size(271, 351)
        Me.treeTwo.TabIndex = 3
        "
        "TreeViewExample
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(520, 366)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.treeTwo, Me.Splitter1, Me.treeOne})
        Me.DockPadding.Bottom = 10
        Me.DockPadding.Left = 5
        Me.DockPadding.Right = 5
        Me.DockPadding.Top = 5
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "TreeViewExample"
        Me.Text = "TreeView Example"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub TreeViewExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim node As TreeNode
        node = treeOne.Nodes.Add("Node 1")
        node.Nodes.Add("Leap 1")
        node.Nodes.Add("Leap 2")
        node.Expand()
        node = treeTwo.Nodes.Add("Node 2")
        node.Nodes.Add("Leap 3")
        node.Nodes.Add("Leap 4")
        node.Expand()
        treeTwo.AllowDrop = True
        treeOne.AllowDrop = True
    End Sub
    Private Sub treeOne_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles treeOne.MouseDown, treeTwo.MouseDown
        Dim tree As TreeView = CType(sender, TreeView)
        Dim node As TreeNode
        node = tree.GetNodeAt(e.X, e.Y)
        tree.SelectedNode = node
        If Not node Is Nothing Then
            tree.DoDragDrop(node.Clone(), DragDropEffects.Copy)
        End If
    End Sub
    Private Sub treeTwo_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragOver, treeTwo.DragOver
        Dim tree As TreeView = CType(sender, TreeView)
        e.Effect = DragDropEffects.None
        If Not e.Data.GetData(GetType(TreeNode)) Is Nothing Then
            Dim pt As New Point(e.X, e.Y)
            pt = tree.PointToClient(pt)
            Dim node As TreeNode = tree.GetNodeAt(pt)
            If Not node Is Nothing Then
                e.Effect = DragDropEffects.Copy
                tree.SelectedNode = node
            End If
        End If
    End Sub
    Private Sub treeTwo_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragDrop, treeTwo.DragDrop
        Dim tree As TreeView = CType(sender, TreeView)
        Dim pt As New Point(e.X, e.Y)
        pt = tree.PointToClient(pt)
        Dim node As TreeNode = tree.GetNodeAt(pt)
        node.Nodes.Add(e.Data.GetData(GetType(TreeNode)))
        node.Expand()
    End Sub
End Class


TreeView.CheckBoxes

  
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class TreeViewSelectionCheckBoxes
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TreeView1 = New System.Windows.Forms.TreeView
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Button1 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "TreeView1
        "
        Me.TreeView1.ImageIndex = -1
        Me.TreeView1.Location = New System.Drawing.Point(88, 64)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Root", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node 1", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node 2"), New System.Windows.Forms.TreeNode("Node 3")}), New System.Windows.Forms.TreeNode("Node 4", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node 5"), New System.Windows.Forms.TreeNode("Node 6")})})})
        Me.TreeView1.SelectedImageIndex = -1
        Me.TreeView1.Size = New System.Drawing.Size(121, 120)
        Me.TreeView1.TabIndex = 0
        "
        "TextBox1
        "
        Me.TextBox1.Location = New System.Drawing.Point(88, 200)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(120, 20)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = ""
        "
        "Button1
        "
        Me.Button1.Location = New System.Drawing.Point(88, 232)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(120, 23)
        Me.Button1.TabIndex = 3
        Me.Button1.Text = "Show Check Boxes"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.TreeView1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        TextBox1.Text = e.Node.Text & " was selected."
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TreeView1.CheckBoxes = True
    End Sub
    Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
        If e.Node.Checked Then
            TextBox1.Text = e.Node.Text & " is checked."
        Else
            TextBox1.Text = e.Node.Text & " is not checked."
        End If
    End Sub
End Class


TreeView.DoDragDrop

  
Imports System
Imports System.Drawing
Imports System.Reflection
Imports System.Windows.Forms
public class MainClass
   Shared Sub Main()
      Dim form1 As Form = New Form1
      Application.Run(form1)
   End Sub
End Class


Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents DestinationTextBox As System.Windows.Forms.TextBox
    Friend WithEvents SourceTextBox As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DestinationTextBox = New System.Windows.Forms.TextBox()
        Me.SourceTextBox = New System.Windows.Forms.TextBox()
        Me.ListBox1 = New System.Windows.Forms.ListBox()
        Me.TreeView1 = New System.Windows.Forms.TreeView()
        Me.SuspendLayout()
        "
        "DestinationTextBox
        "
        Me.DestinationTextBox.AllowDrop = True
        Me.DestinationTextBox.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.DestinationTextBox.Location = New System.Drawing.Point(4, 166)
        Me.DestinationTextBox.Multiline = True
        Me.DestinationTextBox.Name = "DestinationTextBox"
        Me.DestinationTextBox.Size = New System.Drawing.Size(354, 195)
        Me.DestinationTextBox.TabIndex = 1
        Me.DestinationTextBox.Text = ""
        "
        "SourceTextBox
        "
        Me.SourceTextBox.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.SourceTextBox.Location = New System.Drawing.Point(4, 4)
        Me.SourceTextBox.Multiline = True
        Me.SourceTextBox.Name = "SourceTextBox"
        Me.SourceTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
        Me.SourceTextBox.Size = New System.Drawing.Size(354, 144)
        Me.SourceTextBox.TabIndex = 2
        Me.SourceTextBox.Text = "Use your right or left key to drag and drop item in left ListBox or Tree to the bottom TextBox."
        "
        "ListBox1
        "
        Me.ListBox1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.ListBox1.ItemHeight = 14
        Me.ListBox1.Items.AddRange(New Object() {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10", "Item 11", "Item 12", "Item 13", "Item 14", "Item 15"})
        Me.ListBox1.Location = New System.Drawing.Point(370, 4)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
        Me.ListBox1.Size = New System.Drawing.Size(190, 144)
        Me.ListBox1.TabIndex = 3
        "
        "TreeView1
        "
        Me.TreeView1.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.TreeView1.ImageIndex = -1
        Me.TreeView1.Location = New System.Drawing.Point(370, 166)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node0", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node1"), New System.Windows.Forms.TreeNode("Node12", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node13")}), New System.Windows.Forms.TreeNode("Node14"), New System.Windows.Forms.TreeNode("Node15", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node16"), New System.Windows.Forms.TreeNode("Node17")})}), New System.Windows.Forms.TreeNode("Node2", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node3", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node4"), New System.Windows.Forms.TreeNode("Node5"), New System.Windows.Forms.TreeNode("Node6")}), New System.Windows.Forms.TreeNode("Node7"), New System.Windows.Forms.TreeNode("Node8", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node10"), New System.Windows.Forms.TreeNode("Node11")}), New System.Windows.Forms.TreeNode("Node9")})})
        Me.TreeView1.SelectedImageIndex = -1
        Me.TreeView1.Size = New System.Drawing.Size(187, 195)
        Me.TreeView1.TabIndex = 4
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.AutoScroll = True
        Me.ClientSize = New System.Drawing.Size(564, 367)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TreeView1, Me.ListBox1, Me.SourceTextBox, Me.DestinationTextBox})
        Me.Name = "Form1"
        Me.Text = "Drag and Drop Demo"
        Me.ResumeLayout(False)
    End Sub
#End Region

    Private Sub Destination_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DestinationTextBox.DragDrop
        DestinationTextBox.Text = e.Data.GetData(DataFormats.Text).ToString
        DestinationTextBox.BackColor = Color.White
    End Sub
    Private Sub Destination_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DestinationTextBox.DragEnter
        DestinationTextBox.BackColor = Color.Yellow
        e.Effect = DragDropEffects.Copy
    End Sub
    Private Sub SourceTextBox_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles SourceTextBox.MouseDown
        SourceTextBox.DoDragDrop(SourceTextBox.SelectedText, DragDropEffects.Copy Or DragDropEffects.Move)
    End Sub
    Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDown
        Dim i As Integer, selItems As String
        For i = 0 To ListBox1.SelectedItems.Count - 1
            selItems = selItems & ListBox1.SelectedItems.Item(i) & vbCrLf
        Next
        SourceTextBox.DoDragDrop(selItems, DragDropEffects.Copy Or DragDropEffects.Move)
    End Sub
    Private Sub Destination_DragLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DestinationTextBox.DragLeave
        DestinationTextBox.BackColor = Color.White
    End Sub
    Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
        If e.Button = MouseButtons.Right Then
            TreeView1.DoDragDrop(TreeView1.SelectedNode.Text, DragDropEffects.Copy Or DragDropEffects.Move)
        End If
    End Sub
End Class


TreeView.ExpandAll()

  

        
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Data.SqlClient
public class MainClass
   Shared Sub Main()
       Dim form1 As Form = New Form1
       Application.Run(form1)
   End Sub
End Class

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim factory, group, person As TreeNode
        " Create some nodes.
        trvOrgChart.Nodes.Clear()
        factory = trvOrgChart.Nodes.Add("f Name", "Name", 0, 0)
        group = factory.Nodes.Add("g Dept 1", "Dept 2", 1, 1)
        person = group.Nodes.Add("p Name 1", "Name 1", 2, 2)
        person = group.Nodes.Add("p Name 2", "Name 2", 2, 2)
        group = factory.Nodes.Add("g Dep 2", "Dep 2t", 1, 1)
        person = group.Nodes.Add("p Name 1", "Name 1", 2, 2)
        person = group.Nodes.Add("p Name 2", "Name 2", 2, 2)
        factory = trvOrgChart.Nodes.Add( _
            "f Dept 3", "Dept 3", 0, 0)
        group = factory.Nodes.Add( _
            "g Name 1", "Name 1", 1, 1)
        person = group.Nodes.Add( _
            "p Name 2", "Name 2", 2, 2)
        person = group.Nodes.Add( _
            "p Name 3", "Namr 3", 2, 2)
        group = factory.Nodes.Add( _
            "g Dep 5", "Dep 5", 1, 1)
        person = group.Nodes.Add( _
            "p Name 1", "Name 1", 2, 2)
        person = group.Nodes.Add( _
            "p Name 2", "Namr 2", 2, 2)
        person = group.Nodes.Add( _
            "p Name 3", "Name 3", 2, 2)
        group = factory.Nodes.Add( _
            "g Dept 10", "Dept 10", 1, 1)
        person = group.Nodes.Add( _
            "p Name 1", "Namr 1", 2, 2)
        person = group.Nodes.Add( _
            "p Namr 2", "Name 2", 2, 2)
        trvOrgChart.ExpandAll()
        trvOrgChart.Nodes(0).EnsureVisible()
    End Sub
    Private Sub trvOrgChart_BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles trvOrgChart.BeforeLabelEdit
        e.CancelEdit = (e.Node.FullPath.IndexOf(trvOrgChart.PathSeparator) = -1)
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim TreeNode1 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Cameron, Charlie", 2, 5)
        Dim TreeNode2 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Davos, Debbie", 2, 5)
        Dim TreeNode3 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Engineering", 1, 4, New System.Windows.Forms.TreeNode() {TreeNode1, TreeNode2})
        Dim TreeNode4 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Test", 1, 4)
        Dim TreeNode5 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("R & D", 0, 3, New System.Windows.Forms.TreeNode() {TreeNode3, TreeNode4})
        Me.trvOrgChart = New System.Windows.Forms.TreeView
        Me.SuspendLayout()
        "
        "trvOrgChart
        "
        Me.trvOrgChart.Dock = System.Windows.Forms.DockStyle.Fill
        Me.trvOrgChart.ImageIndex = 0
        Me.trvOrgChart.LabelEdit = True
        Me.trvOrgChart.Location = New System.Drawing.Point(0, 0)
        Me.trvOrgChart.Name = "trvOrgChart"
        TreeNode1.Name = "Node6"
        TreeNode1.SelectedImageIndex = 5
        TreeNode1.Text = "Cameron, Charlie"
        TreeNode2.Name = "Node7"
        TreeNode2.SelectedImageIndex = 5
        TreeNode2.Text = "Davos, Debbie"
        TreeNode3.ImageIndex = 1
        TreeNode3.Name = "Node5"
        TreeNode3.SelectedImageIndex = 4
        TreeNode3.Text = "Engineering"
        TreeNode4.ImageIndex = 1
        TreeNode4.Name = "Node8"
        TreeNode4.SelectedImageIndex = 4
        TreeNode4.Text = "Test"
        TreeNode5.ImageIndex = 0
        TreeNode5.Name = "Node0"
        TreeNode5.SelectedImageIndex = 3
        TreeNode5.Text = "R & D"
        Me.trvOrgChart.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode5})
        Me.trvOrgChart.SelectedImageIndex = 0
        Me.trvOrgChart.Size = New System.Drawing.Size(292, 273)
        Me.trvOrgChart.TabIndex = 1
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.trvOrgChart)
        Me.Name = "Form1"
        Me.Text = "UseTreeView"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents trvOrgChart As System.Windows.Forms.TreeView
End Class


TreeView.GetNodeAt

  

Imports System
Imports System.Collections
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ruponentModel
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1
        Application.Run(form1)

    End Sub
End Class


Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents treeOne As System.Windows.Forms.TreeView
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents treeTwo As System.Windows.Forms.TreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.treeOne = New System.Windows.Forms.TreeView()
        Me.Splitter1 = New System.Windows.Forms.Splitter()
        Me.treeTwo = New System.Windows.Forms.TreeView()
        Me.SuspendLayout()
        "
        "treeOne
        "
        Me.treeOne.Dock = System.Windows.Forms.DockStyle.Left
        Me.treeOne.HideSelection = False
        Me.treeOne.ImageIndex = -1
        Me.treeOne.Location = New System.Drawing.Point(5, 5)
        Me.treeOne.Name = "treeOne"
        Me.treeOne.SelectedImageIndex = -1
        Me.treeOne.Size = New System.Drawing.Size(236, 351)
        Me.treeOne.TabIndex = 0
        "
        "Splitter1
        "
        Me.Splitter1.Location = New System.Drawing.Point(241, 5)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 351)
        Me.Splitter1.TabIndex = 2
        Me.Splitter1.TabStop = False
        "
        "treeTwo
        "
        Me.treeTwo.Dock = System.Windows.Forms.DockStyle.Fill
        Me.treeTwo.HideSelection = False
        Me.treeTwo.ImageIndex = -1
        Me.treeTwo.Location = New System.Drawing.Point(244, 5)
        Me.treeTwo.Name = "treeTwo"
        Me.treeTwo.SelectedImageIndex = -1
        Me.treeTwo.Size = New System.Drawing.Size(271, 351)
        Me.treeTwo.TabIndex = 3
        "
        "TreeViewExample
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(520, 366)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.treeTwo, Me.Splitter1, Me.treeOne})
        Me.DockPadding.Bottom = 10
        Me.DockPadding.Left = 5
        Me.DockPadding.Right = 5
        Me.DockPadding.Top = 5
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "TreeViewExample"
        Me.Text = "TreeView Example"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub TreeViewExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim node As TreeNode
        node = treeOne.Nodes.Add("Node 1")
        node.Nodes.Add("Leap 1")
        node.Nodes.Add("Leap 2")
        node.Expand()
        node = treeTwo.Nodes.Add("Node 2")
        node.Nodes.Add("Leap 3")
        node.Nodes.Add("Leap 4")
        node.Expand()
        treeTwo.AllowDrop = True
        treeOne.AllowDrop = True
    End Sub
    Private Sub treeOne_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles treeOne.MouseDown, treeTwo.MouseDown
        Dim tree As TreeView = CType(sender, TreeView)
        Dim node As TreeNode
        node = tree.GetNodeAt(e.X, e.Y)
        tree.SelectedNode = node
        If Not node Is Nothing Then
            tree.DoDragDrop(node.Clone(), DragDropEffects.Copy)
        End If
    End Sub
    Private Sub treeTwo_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragOver, treeTwo.DragOver
        Dim tree As TreeView = CType(sender, TreeView)
        e.Effect = DragDropEffects.None
        If Not e.Data.GetData(GetType(TreeNode)) Is Nothing Then
            Dim pt As New Point(e.X, e.Y)
            pt = tree.PointToClient(pt)
            Dim node As TreeNode = tree.GetNodeAt(pt)
            If Not node Is Nothing Then
                e.Effect = DragDropEffects.Copy
                tree.SelectedNode = node
            End If
        End If
    End Sub
    Private Sub treeTwo_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragDrop, treeTwo.DragDrop
        Dim tree As TreeView = CType(sender, TreeView)
        Dim pt As New Point(e.X, e.Y)
        pt = tree.PointToClient(pt)
        Dim node As TreeNode = tree.GetNodeAt(pt)
        node.Nodes.Add(e.Data.GetData(GetType(TreeNode)))
        node.Expand()
    End Sub
End Class


TreeView.Nodes

  
        
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Data.SqlClient
public class MainClass
   Shared Sub Main()
       Dim form1 As Form = New Form1
       Application.Run(form1)
   End Sub
End Class

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim factory, group, person As TreeNode
        " Create some nodes.
        trvOrgChart.Nodes.Clear()
        factory = trvOrgChart.Nodes.Add("f Name", "Name", 0, 0)
        group = factory.Nodes.Add("g Dept 1", "Dept 2", 1, 1)
        person = group.Nodes.Add("p Name 1", "Name 1", 2, 2)
        person = group.Nodes.Add("p Name 2", "Name 2", 2, 2)
        group = factory.Nodes.Add("g Dep 2", "Dep 2t", 1, 1)
        person = group.Nodes.Add("p Name 1", "Name 1", 2, 2)
        person = group.Nodes.Add("p Name 2", "Name 2", 2, 2)
        factory = trvOrgChart.Nodes.Add( _
            "f Dept 3", "Dept 3", 0, 0)
        group = factory.Nodes.Add( _
            "g Name 1", "Name 1", 1, 1)
        person = group.Nodes.Add( _
            "p Name 2", "Name 2", 2, 2)
        person = group.Nodes.Add( _
            "p Name 3", "Namr 3", 2, 2)
        group = factory.Nodes.Add( _
            "g Dep 5", "Dep 5", 1, 1)
        person = group.Nodes.Add( _
            "p Name 1", "Name 1", 2, 2)
        person = group.Nodes.Add( _
            "p Name 2", "Namr 2", 2, 2)
        person = group.Nodes.Add( _
            "p Name 3", "Name 3", 2, 2)
        group = factory.Nodes.Add( _
            "g Dept 10", "Dept 10", 1, 1)
        person = group.Nodes.Add( _
            "p Name 1", "Namr 1", 2, 2)
        person = group.Nodes.Add( _
            "p Namr 2", "Name 2", 2, 2)
        trvOrgChart.ExpandAll()
        trvOrgChart.Nodes(0).EnsureVisible()
    End Sub
    Private Sub trvOrgChart_BeforeLabelEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.NodeLabelEditEventArgs) Handles trvOrgChart.BeforeLabelEdit
        e.CancelEdit = (e.Node.FullPath.IndexOf(trvOrgChart.PathSeparator) = -1)
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim TreeNode1 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Cameron, Charlie", 2, 5)
        Dim TreeNode2 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Davos, Debbie", 2, 5)
        Dim TreeNode3 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Engineering", 1, 4, New System.Windows.Forms.TreeNode() {TreeNode1, TreeNode2})
        Dim TreeNode4 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("Test", 1, 4)
        Dim TreeNode5 As System.Windows.Forms.TreeNode = New System.Windows.Forms.TreeNode("R & D", 0, 3, New System.Windows.Forms.TreeNode() {TreeNode3, TreeNode4})
        Me.trvOrgChart = New System.Windows.Forms.TreeView
        Me.SuspendLayout()
        "
        "trvOrgChart
        "
        Me.trvOrgChart.Dock = System.Windows.Forms.DockStyle.Fill
        Me.trvOrgChart.ImageIndex = 0
        Me.trvOrgChart.LabelEdit = True
        Me.trvOrgChart.Location = New System.Drawing.Point(0, 0)
        Me.trvOrgChart.Name = "trvOrgChart"
        TreeNode1.Name = "Node6"
        TreeNode1.SelectedImageIndex = 5
        TreeNode1.Text = "Cameron, Charlie"
        TreeNode2.Name = "Node7"
        TreeNode2.SelectedImageIndex = 5
        TreeNode2.Text = "Davos, Debbie"
        TreeNode3.ImageIndex = 1
        TreeNode3.Name = "Node5"
        TreeNode3.SelectedImageIndex = 4
        TreeNode3.Text = "Engineering"
        TreeNode4.ImageIndex = 1
        TreeNode4.Name = "Node8"
        TreeNode4.SelectedImageIndex = 4
        TreeNode4.Text = "Test"
        TreeNode5.ImageIndex = 0
        TreeNode5.Name = "Node0"
        TreeNode5.SelectedImageIndex = 3
        TreeNode5.Text = "R & D"
        Me.trvOrgChart.Nodes.AddRange(New System.Windows.Forms.TreeNode() {TreeNode5})
        Me.trvOrgChart.SelectedImageIndex = 0
        Me.trvOrgChart.Size = New System.Drawing.Size(292, 273)
        Me.trvOrgChart.TabIndex = 1
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.Add(Me.trvOrgChart)
        Me.Name = "Form1"
        Me.Text = "UseTreeView"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents trvOrgChart As System.Windows.Forms.TreeView
End Class


TreeView.PointToClient

  
Imports System
Imports System.Collections
Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ruponentModel
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1
        Application.Run(form1)

    End Sub
End Class


Public Class Form1
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents treeOne As System.Windows.Forms.TreeView
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents treeTwo As System.Windows.Forms.TreeView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.treeOne = New System.Windows.Forms.TreeView()
        Me.Splitter1 = New System.Windows.Forms.Splitter()
        Me.treeTwo = New System.Windows.Forms.TreeView()
        Me.SuspendLayout()
        "
        "treeOne
        "
        Me.treeOne.Dock = System.Windows.Forms.DockStyle.Left
        Me.treeOne.HideSelection = False
        Me.treeOne.ImageIndex = -1
        Me.treeOne.Location = New System.Drawing.Point(5, 5)
        Me.treeOne.Name = "treeOne"
        Me.treeOne.SelectedImageIndex = -1
        Me.treeOne.Size = New System.Drawing.Size(236, 351)
        Me.treeOne.TabIndex = 0
        "
        "Splitter1
        "
        Me.Splitter1.Location = New System.Drawing.Point(241, 5)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 351)
        Me.Splitter1.TabIndex = 2
        Me.Splitter1.TabStop = False
        "
        "treeTwo
        "
        Me.treeTwo.Dock = System.Windows.Forms.DockStyle.Fill
        Me.treeTwo.HideSelection = False
        Me.treeTwo.ImageIndex = -1
        Me.treeTwo.Location = New System.Drawing.Point(244, 5)
        Me.treeTwo.Name = "treeTwo"
        Me.treeTwo.SelectedImageIndex = -1
        Me.treeTwo.Size = New System.Drawing.Size(271, 351)
        Me.treeTwo.TabIndex = 3
        "
        "TreeViewExample
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(520, 366)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.treeTwo, Me.Splitter1, Me.treeOne})
        Me.DockPadding.Bottom = 10
        Me.DockPadding.Left = 5
        Me.DockPadding.Right = 5
        Me.DockPadding.Top = 5
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Name = "TreeViewExample"
        Me.Text = "TreeView Example"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub TreeViewExample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim node As TreeNode
        node = treeOne.Nodes.Add("Node 1")
        node.Nodes.Add("Leap 1")
        node.Nodes.Add("Leap 2")
        node.Expand()
        node = treeTwo.Nodes.Add("Node 2")
        node.Nodes.Add("Leap 3")
        node.Nodes.Add("Leap 4")
        node.Expand()
        treeTwo.AllowDrop = True
        treeOne.AllowDrop = True
    End Sub
    Private Sub treeOne_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles treeOne.MouseDown, treeTwo.MouseDown
        Dim tree As TreeView = CType(sender, TreeView)
        Dim node As TreeNode
        node = tree.GetNodeAt(e.X, e.Y)
        tree.SelectedNode = node
        If Not node Is Nothing Then
            tree.DoDragDrop(node.Clone(), DragDropEffects.Copy)
        End If
    End Sub
    Private Sub treeTwo_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragOver, treeTwo.DragOver
        Dim tree As TreeView = CType(sender, TreeView)
        e.Effect = DragDropEffects.None
        If Not e.Data.GetData(GetType(TreeNode)) Is Nothing Then
            Dim pt As New Point(e.X, e.Y)
            pt = tree.PointToClient(pt)
            Dim node As TreeNode = tree.GetNodeAt(pt)
            If Not node Is Nothing Then
                e.Effect = DragDropEffects.Copy
                tree.SelectedNode = node
            End If
        End If
    End Sub
    Private Sub treeTwo_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles treeOne.DragDrop, treeTwo.DragDrop
        Dim tree As TreeView = CType(sender, TreeView)
        Dim pt As New Point(e.X, e.Y)
        pt = tree.PointToClient(pt)
        Dim node As TreeNode = tree.GetNodeAt(pt)
        node.Nodes.Add(e.Data.GetData(GetType(TreeNode)))
        node.Expand()
    End Sub
End Class


TreeView.SelectedNode

  
Imports System.Windows.Forms
public class TreeViewAddDeleteItem
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ruponentModel.IContainer
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TreeView1 = New System.Windows.Forms.TreeView
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.SuspendLayout()
        "
        "TreeView1
        "
        Me.TreeView1.ImageIndex = -1
        Me.TreeView1.Location = New System.Drawing.Point(48, 16)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("a", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Visual Basic"), New System.Windows.Forms.TreeNode("Visual C++"), New System.Windows.Forms.TreeNode("Delphi"), New System.Windows.Forms.TreeNode("Java")}), New System.Windows.Forms.TreeNode("B", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("B1"), New System.Windows.Forms.TreeNode("B2"), New System.Windows.Forms.TreeNode("B3"), New System.Windows.Forms.TreeNode("B4")})})
        Me.TreeView1.SelectedImageIndex = -1
        Me.TreeView1.Size = New System.Drawing.Size(200, 168)
        Me.TreeView1.TabIndex = 0
        "
        "Button1
        "
        Me.Button1.Location = New System.Drawing.Point(48, 200)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 24)
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "Add"
        "
        "Button2
        "
        Me.Button2.Location = New System.Drawing.Point(176, 200)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(80, 24)
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "Delete"
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 238)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.TreeView1)
        Me.ResumeLayout(False)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str As New TreeNode
        TreeView1.SelectedNode.Nodes.Add("New")
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TreeView1.Nodes.Remove(TreeView1.SelectedNode)
    End Sub
End Class