
TreeView -Click Event on Plus Sign Node
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.ComponentModel.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 Button1 As System.Windows.Forms.Button
<System.Diagnostics.De{*filter*}StepThrough()> Private Sub
InitializeComponent()
Me.TreeView1 = New System.Windows.Forms.TreeView()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'TreeView1
'
Me.TreeView1.ImageIndex = -1
Me.TreeView1.Location = New System.Drawing.Point(40, 16)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.SelectedImageIndex = -1
Me.TreeView1.Size = New System.Drawing.Size(360, 456)
Me.TreeView1.TabIndex = 0
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(464, 32)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(112, 32)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(744, 518)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1,
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
End Sub
Private Sub TreeView1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TreeView1.Click
TreeView1.Cursor = System.Windows.Forms.Cursors.Hand
TreeView1.Cursor.Show()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Node As TreeNode
Node = TreeView1.Nodes.Add("")
Node.Nodes.Add("")
End Sub
Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand
Dim Node As TreeNode
Dim Node1 As TreeNode
Node = TreeView1.SelectedNode
Node.Nodes.Remove(TreeView1.SelectedNode.Nodes(0))
Node.Text = "Hello"
Node.Nodes.Add("World")
End Sub
End Class
HTH
Quote:
> Richard,
> Thanks for the sample code, it works fine, the main node got selected
> at the time of form load,
> In my case I have too many node sub node, sub sub node and so on..
> don't want to creat all of them at once, so added the (+) plus sign to
> represent the node which is having the sub node without adding real
> sub nodes (just by adding single dummy node), what I wanted now is,
> when the user clicks on the (+) plus sign, I want read the node,
> delete the dummy node before user see this dummy node, which was
> created to add the + sign and generate the real sub nodes.
> I appreciate your help or tips in this issue.
> Thanks,
> Sudhakar