网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 大学论文导航 设计下载 最新论文 下载排行 原创论文 论文源代码
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > ASP.net > 正文

自定义的TreeView

来源:http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 14/02/25

以下是网学网为您推荐的ASP.net-自定义的TreeView,希望本篇文章对您学习有所帮助。

CustomTreeViewForm类,好东西大家分享,好好研究一下哦!
Public Class CustomTreeViewForm
    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
        InitializeForm()
    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 tvwCategories As System.Windows.Forms.TreeView
    Friend WithEvents txtSelectedID As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.tvwCategories = New System.Windows.Forms.TreeView()
        Me.txtSelectedID = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        ''
        ''tvwCategories
        ''
        Me.tvwCategories.ImageIndex = -1
        Me.tvwCategories.Location = New System.Drawing.Point(7, 2)
        Me.tvwCategories.Name = "tvwCategories"
        Me.tvwCategories.SelectedImageIndex = -1
        Me.tvwCategories.Size = New System.Drawing.Size(277, 240)
        Me.tvwCategories.TabIndex = 0
        ''
        ''txtSelectedID
        ''
        Me.txtSelectedID.Location = New System.Drawing.Point(6, 246)
        Me.txtSelectedID.Name = "txtSelectedID"
        Me.txtSelectedID.Size = New System.Drawing.Size(278, 20)
        Me.txtSelectedID.TabIndex = 1
        Me.txtSelectedID.Text = "txtSelectedID"
        ''
        ''CustomTreeViewForm
        ''
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtSelectedID, Me.tvwCategories})
        Me.Name = "CustomTreeViewForm"
        Me.Text = "Custom TreeView"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub InitializeForm()
        Dim objCategories As New Categories()
        Dim i As Integer
        Dim x As Integer
        For i = 1 To 5
            With objCategories.Add(New Category())
                .CategoryID = "CAT" & i
                .DisplayName = "Category " & i
                For x = 1 To 3
                    With .AccountTypes.Add(New AccountType())
                        .AccountTypeID = "A" & x
                        .DisplayName = "AccountType " & x
                    End With
                    With .PartTypes.Add(New PartType())
                        .PartTypeID = "P" & x
                        .DisplayName = "PartType " & x
                    End With
                Next x
            End With
        Next i
        With Me.tvwCategories
            Dim objCategory As Category
            Dim objAccountType As AccountType
            Dim objPartType As PartType
            Dim objCategoryTreeNode As CategoryTreeNode
            For Each objCategory In objCategories
                objCategoryTreeNode = New CategoryTreeNode(objCategory)
                .Nodes.Add(objCategoryTreeNode)
                With objCategoryTreeNode
                    For Each objAccountType In objCategory.AccountTypes
                        .Nodes.Add(New AccountTypeTreeNode(objAccountType))
                    Next
                    For Each objPartType In objCategory.PartTypes
                        .Nodes.Add(New PartTypeTreeNode(objPartType))
                    Next
                End With
            Next
        End With
    End Sub

    Private Sub tvwCategories_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwCategories.AfterSelect
        Dim objNode As TreeNode
        objNode = tvwCategories.SelectedNode
        Select Case objNode.GetType.ToString
            Case "CustomTreeView.CategoryTreeNode"
                Dim objCategoryTreeNode As CategoryTreeNode
                objCategoryTreeNode = CType(objNode, CategoryTreeNode)
                txtSelectedID.Text = objCategoryTreeNode.Category.CategoryID.ToString
            Case "CustomTreeView.AccountTypeTreeNode"
                Dim objAccountTypeTreeNode As AccountTypeTreeNode
                objAccountTypeTreeNode = CType(objNode, AccountTypeTreeNode)
                txtSelectedID.Text = objAccountTypeTreeNode.AccountType.AccountTypeID.ToString
            Case "CustomTreeView.PartTypeTreeNode"
                Dim objPartTypeTreeNode As PartTypeTreeNode
                objPartTypeTreeNode = CType(objNode, PartTypeTreeNode)
                txtSelectedID.Text = objPartTypeTreeNode.PartType.PartTypeID.ToString
        End Select
    End Sub
End Class
Public Class AccountType
    Public AccountTypeID As String
    Public DisplayName As String
End Class
Public Class PartType
    Public PartTypeID As String
    Public DisplayName As String
End Class
Public Class Category
    Public CategoryID As String
    Public DisplayName As String
    Public AccountTypes As New AccountTypes()
    Public PartTypes As New PartTypes()
End Class
Public Class Categories
    Inherits CollectionBase
    Public Function Add(ByVal value As Category) As Category
        Me.InnerList.Add(value)
        Add = value
    End Function
End Class
Public Class AccountTypes
    Inherits CollectionBase
    Public Function Add(ByVal value As AccountType) As AccountType
        Me.InnerList.Add(value)
        Add = value
    End Function
End Class
Public Class PartTypes
    Inherits CollectionBase
    Public Function Add(ByVal value As PartType) As PartType
        Me.InnerList.Add(value)
        Add = value
    End Function
End Class
Public Class AccountTypeTreeNode
    Inherits TreeNode
    Public AccountType As AccountType
    Sub New(ByVal Value As AccountType)
        MyBase.New()
        AccountType = Value
        Me.Text = AccountType.DisplayName
    End Sub
End Class
Public Class PartTypeTreeNode
    Inherits TreeNode
    Public PartType As PartType
    Sub New(ByVal Value As PartType)
        MyBase.New()
        PartType = Value
        Me.Text = PartType.DisplayName
    End Sub
End Class
Public Class CategoryTreeNode
    Inherits TreeNode
    Public Category As Category
    Sub New(ByVal Value As Category)
        MyBase.New()
        Category = Value
        Me.Text = Category.DisplayName
    End Sub
End Class
  • 上一篇资讯: Repeater控件的使用
  • 网学推荐

    免费论文

    原创论文

    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号