本文整理汇总了VB.NET中System.Windows.Forms.TreeView.Nodes属性的典型用法代码示例。如果您正苦于以下问题:VB.NET TreeView.Nodes属性的具体用法?VB.NET TreeView.Nodes怎么用?VB.NET TreeView.Nodes使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.TreeView
的用法示例。
在下文中一共展示了TreeView.Nodes属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Customer
Public Class Customer
Inherits [Object]
Private custName As String = ""
Friend custOrders As New ArrayList()
Public Sub New(ByVal customername As String)
Me.custName = customername
End Sub
Public Property CustomerName() As String
Get
Return Me.custName
End Get
Set(ByVal Value As String)
Me.custName = Value
End Set
End Property
Public ReadOnly Property CustomerOrders() As ArrayList
Get
Return Me.custOrders
End Get
End Property
End Class
Public Class Order
Inherits [Object]
Private ordID As String
Public Sub New(ByVal orderid As String)
Me.ordID = orderid
End Sub
Public Property OrderID() As String
Get
Return Me.ordID
End Get
Set(ByVal Value As String)
Me.ordID = Value
End Set
End Property
End Class
' Create a new ArrayList to hold the Customer objects.
Private customerArray As New ArrayList()
Private Sub FillMyTreeView()
' Add customers to the ArrayList of Customer objects.
Dim x As Integer
For x = 0 To 999
customerArray.Add(New Customer("Customer" + x.ToString()))
Next x
' Add orders to each Customer object in the ArrayList.
Dim customer1 As Customer
For Each customer1 In customerArray
Dim y As Integer
For y = 0 To 14
customer1.CustomerOrders.Add(New Order("Order" + y.ToString()))
Next y
Next customer1
' Display a wait cursor while the TreeNodes are being created.
Cursor.Current = New Cursor("MyWait.cur")
' Suppress repainting the TreeView until all the objects have been created.
treeView1.BeginUpdate()
' Clear the TreeView each time the method is called.
treeView1.Nodes.Clear()
' Add a root TreeNode for each Customer object in the ArrayList.
Dim customer2 As Customer
For Each customer2 In customerArray
treeView1.Nodes.Add(New TreeNode(customer2.CustomerName))
' Add a child TreeNode for each Order object in the current Customer object.
Dim order1 As Order
For Each order1 In customer2.CustomerOrders
treeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _
New TreeNode(customer2.CustomerName + "." + order1.OrderID))
Next order1
Next customer2
' Reset the cursor to the default for all controls.
Cursor.Current = System.Windows.Forms.Cursors.Default
' Begin repainting the TreeView.
treeView1.EndUpdate()
End Sub
示例2: MainClass
' 导入命名空间
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.CompilerServices.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.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.
<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