Tree Node selection event : TreeView « GUI « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » GUI » TreeView 
14.42.5.Tree Node selection event
Tree Node selection event
Imports System.Windows.Forms

public class SplitterControl
   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 NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents Splitter2 As System.Windows.Forms.Splitter
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Splitter3 As System.Windows.Forms.Splitter
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Me.Splitter1 = New System.Windows.Forms.Splitter
        Me.TreeView1 = New System.Windows.Forms.TreeView
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.Splitter2 = New System.Windows.Forms.Splitter
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Label1 = New System.Windows.Forms.Label
        Me.Splitter3 = New System.Windows.Forms.Splitter
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Splitter1
        '
        Me.Splitter1.Location = New System.Drawing.Point(00)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3266)
        Me.Splitter1.TabIndex = 0
        Me.Splitter1.TabStop = False
        '
        'TreeView1
        '
        Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Left
        Me.TreeView1.Location = New System.Drawing.Point(30)
        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("1"), New System.Windows.Forms.TreeNode("2"), New System.Windows.Forms.TreeNode("3"), New System.Windows.Forms.TreeNode("4")})})
        Me.TreeView1.Size = New System.Drawing.Size(101266)
        Me.TreeView1.TabIndex = 1
        '
        'Splitter2
        '
        Me.Splitter2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Splitter2.Location = New System.Drawing.Point(1040)
        Me.Splitter2.Name = "Splitter2"
        Me.Splitter2.Size = New System.Drawing.Size(8266)
        Me.Splitter2.TabIndex = 2
        Me.Splitter2.TabStop = False
        '
        'Panel1
        '
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel1.Controls.Add(Me.ListView1)
        Me.Panel1.Controls.Add(Me.Splitter3)
        Me.Panel1.Controls.Add(Me.Label1)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Panel1.Location = New System.Drawing.Point(1120)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(248264)
        Me.Panel1.TabIndex = 3
        '
        'Label1
        '
        Me.Label1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Label1.Location = New System.Drawing.Point(00)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(24432)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Label1"
        '
        'Splitter3
        '
        Me.Splitter3.Dock = System.Windows.Forms.DockStyle.Top
        Me.Splitter3.Location = New System.Drawing.Point(032)
        Me.Splitter3.Name = "Splitter3"
        Me.Splitter3.Size = New System.Drawing.Size(2448)
        Me.Splitter3.TabIndex = 1
        Me.Splitter3.TabStop = False
        '
        'ListView1
        '
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.ListView1.Location = New System.Drawing.Point(040)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(244220)
        Me.ListView1.TabIndex = 2
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(360266)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.Splitter2)
        Me.Controls.Add(Me.TreeView1)
        Me.Controls.Add(Me.Splitter1)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgsHandles TreeView1.AfterSelect
        Dim childnum, index, i As Int32
        childnum = TreeView1.SelectedNode.GetNodeCount(False)
        index = TreeView1.SelectedNode.Index
        index = index + 1
        ListView1.Items.Clear()
        For i = To childnum - 1
            ListView1.Items.Add(index.ToString + "." + i.ToString, 1)
        Next
        Label1.Text = TreeView1.SelectedNode.FullPath
    End Sub
End Class
14.42.TreeView
14.42.1.Creating Tree Views in CodeCreating Tree Views in Code
14.42.2.Add and remove tree nodesAdd and remove tree nodes
14.42.3.Build file tree recursivelyBuild file tree recursively
14.42.4.Using a TreeView to display the directory structureUsing a TreeView to display the directory structure
14.42.5.Tree Node selection eventTree Node selection event
14.42.6.TreeView CheckBoxTreeView CheckBox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.