Ok, hier ein einfaches Beispiel:
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Vom Windows Form Designer generierter Code "
Public Sub New()
MyBase.New()
' Dieser Aufruf ist für den Windows Form-Designer erforderlich.
InitializeComponent()
' Initialisierungen nach dem Aufruf InitializeComponent() hinzufügen
End Sub
' Die Form überschreibt den Löschvorgang der Basisklasse, um Komponenten zu
' bereinigen.
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
' Für Windows Form-Designer erforderlich
Private components As System.ComponentModel.IContainer
'HINWEIS: Die folgende Prozedur ist für den Windows Form-Designer
' erforderlich
'Sie kann mit dem Windows Form-Designer modifiziert werden.
'Verwenden Sie nicht den Code-Editor zur Bearbeitung.
Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TreeView1 = New System.Windows.Forms.TreeView
Me.SuspendLayout()
'
'TreeView1
'
Me.TreeView1.ImageIndex = -1
Me.TreeView1.Location = New System.Drawing.Point(8, 16)
Me.TreeView1.Name = "TreeView1"
Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New _
System.Windows.Forms.TreeNode("Knoten0", New _
System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode( _
"Knoten1", New System.Windows.Forms.TreeNode() {New _
System.Windows.Forms.TreeNode("Knoten2", New _
System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode( _
"Knoten3"), New System.Windows.Forms.TreeNode("Knoten4", New _
System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode( _
"Knoten5")})}), New System.Windows.Forms.TreeNode("Knoten6", New _
System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode( _
"Knoten7"), New System.Windows.Forms.TreeNode("Knoten8", New _
System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode( _
"Knoten9"), New System.Windows.Forms.TreeNode("Knoten10", New _
System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode( _
"Knoten11")})})})})})})
Me.TreeView1.SelectedImageIndex = -1
Me.TreeView1.Size = New System.Drawing.Size(264, 248)
Me.TreeView1.TabIndex = 0
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.TreeView1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub TreeView1_BeforeSelect(ByVal sender As Object, ByVal e As _
System.Windows.Forms.TreeViewCancelEventArgs) Handles _
TreeView1.BeforeSelect
e.Cancel = (e.Action = TreeViewAction.ByMouse AndAlso _
(e.Node.Text = "Knoten2" OrElse e.Node.Text = "Knoten4"))
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.TreeView1.ExpandAll()
End Sub
End Class (Knoten2 + 4 ist deaktiviert und lässt sich nicht markieren) |