继承创建自定义的TreeView

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

时间: 2024-09-15 19:43:59

继承创建自定义的TreeView的相关文章

在ASP.NET Atlas中创建自定义的Behavior

asp.net|创建 English Version: http://dflying.dflying.net/1/archive/120_build_your_own_behaviors_in_aspnet_atlas.html Atlas中的Behavior定义了当控件的某个事件被触发时的行为.Behavior可以看作是一种封装了的DHTML的事件,例如click和hover等.Behavior同样可以是一个组件,可被attach到某个Atlas客户端控件上,以提供这个Atlas客户端控件更高

在ASP.NET Atlas中创建自定义Action

asp.net|创建 Action是ASP.NET Atlas中继承于Sys.Action基类的的一类组件,用来实现一类由某个事件引发的事件处理功能.Action与事件处理函数的功能类似,但它是一类泛化了的事件处理组件,用来描述一些常见的,通用的事件处理方法,例如调用某个方法,设定某个对象的某个属性,引发一个PostBack等. 我们都知道,目前为止,Atlas最好的参考手册就是它的源代码.我们可以从源代码中找到如下三种Atlas的内建Action,他们都继承于Sys.Action基类: Sys

在ASP.NET Atlas中创建自定义Behavior

asp.net|创建 Atlas中的Behavior定义了当控件的某个事件被触发时的行为.Behavior可以看作是一种封装了的DHTML的事件,例如click和hover等.Behavior同样可以是一个组件,可被attach到某个Atlas客户端控件上,以提供这个Atlas客户端控件更高级,更丰富的功能,例如一些复杂的拖放(drag & drop),自动完成,浮动等功能.Behavior将被定义在某个Atlas控件的behaviors集合中. 从Atlas文档以及源文件中,我们可以知道Atl

用ASP.NET创建自定义文本框

asp.net|创建|文本框 在一个.NET的应用程序中使用自己创建的控件可以大大增强应用程序的功能,你可以在原有控件的基础上加入想要的属性和行为,甚至创建自定义的控件.在asp.net中,我们更可以往一些控件中增加一些客户端的javascript功能,减少每次在提交页面时将数据返回给服务器的次数 ,从而提高程序的功能和效率.在这篇文章中,我们将看下,如何用asp.net创建一个自定义的文本框控件,当焦点在该文本框控件上及离开控件时,文本框控件的背景颜色会随之改变.这个控件将包含如下的功能: 1

《WCF技术内幕》36:第2部分_第6章_通道:创建自定义通道和本章小结

创建自定义通道 上一节已经看过了通道层里的基本类型,现在我们就来创建一个自定义通道 .这个通道的目的就是要在控制台窗口里打印一个文本.因此,我们构建的通道 对于演示通道的生命周期和程序调用不同的通道成员的时候都会非常有用.因为 我们的自定义通道会在控制台窗口打印文本,所以有必要传递通道方法的委托调 用给堆栈里的下一个通道.我们会把这个通道成为委托通道(DelegatorChannel ).在开始之前,有必要指出的是,这里还看不到一个通道运行必须的全部代码 ,直到第8章"绑定"会全部给出

AngularJS创建自定义指令的方法详解_AngularJS

本文实例讲述了AngularJS创建自定义指令的方法.分享给大家供大家参考,具体如下: 这是一篇译文,来自angular开发者说明的指令.主要面向已经熟悉angular开发基础的开发者.这篇文档解释了什么情况下需要创建自己的指令,和如何去创建指令. 什么是指令 从一个高的层面来讲,指令是angular $compile服务的说明,当特定的标签(属性,元素名,或者注释) 出现在DOM中的时候,它让编译器附加指定的行为到DOM上. 这个过程是很简单的.angular内部有很用这样自带的指令,比如说n

Enterprise Library Policy Injection Application Block 之三:PIAB的扩展—创建自定义CallHandler(提供Source Code下载)

本系列的第一部分对PIAB使用场景进行了简单的介绍,作中阐述了通过PI(Policy Injection)的方式实现了Business Logic和Non-Business Infrastructure Logic的分离,从而实现了AOP(Aspect Oriented Programming).在第二部分中详细介绍PIAB的实现机制:通过自定义RealProxy的方式实现了Method Injection.通过这几天接收到的网友的留言,觉得很多人对在具体的项目开发中如何使用PIAB还有很多困惑

使用 ConfigurationSection 创建自定义配置节

我们可以通过用自己的 XML 配置元素来扩展标准的 ASP.NET 配置设置集,要完成这一功能,我们必须实现继承System.Configuration.ConfigurationSection 类来实现自定义配置节,在1.0中当然也可以通过IconfigurationSectionHandler 接口创建自定义配置节!这里我们主要学一下通过ConfigurationSection类来实现简单的配置处理程序.       先看一下在web.config文件中的配置情况,在这里有两个元素,第一个m

【COCOS2DX-LUA 脚本开发之五】LUA 使用OOP(面对对象思想编程),免BINDING创建自定义LUA类

本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/lua-game/1282.html 上一篇中,向童鞋们介绍了如何自定义类binding到Lua中供给使用的教程,那么本篇将介绍利用OOP思想在在Lua中进行创建一个自定义类.    首先Himi来向大家讲解如何在Lua中不binding来自定义lua类,其实这种方式在Cocos2dx的Lua Samples已经为我们做好了例子,就看童鞋们是否