分享
 
 
 

vbscript版的TreeView,也就是树

王朝vb·作者佚名  2006-12-16
窄屏简体版  字體: |||超大  

'=======================================================

'===efei Super TreeView

'===Code By efei(草不含羞)

'===Mailto:efei731@sina.com

'===2004.7

'=======================================================

Dim tvwRoot

Dim tvwChild

Dim tvwPrevious

Dim tvwNext

tvwRoot = 0

tvwChild = 1

tvwPrevious = 2

tvwNext = 3

'===树的类

Class TreeView

?Public Name???'对象名

?Public TreeView_Name

?

?Private ArrNodes??'节点集合,从0开始

?

?Private ArrImage??'图标数组

?

?

?

?

?Private AddFromExpand??'节点的添加是否来自于父节点的展开

?

?'===一些设置

?

?Public FirstDisplayLevel?'初次显示几层

?Public UseConnectLine??'使用节点之间的连接线

?'Public ImagePath???'图象目录

?Public Target????'链接目标

?Public Font_Size???'文字大小

?Public Font_Family???'字体

?Public Font_Color???'颜色

?Public SelectedBgcolor??'选中的节点背景色

?

?'===图象目录=============================

?Private lImagePath???

?Public Property Get ImagePath()

??ImagePath = lImagePath

?End Property

?Public Property Let ImagePath(ByVal vNewValue)

??'更新之前先去掉原来的节点的边框

??lImagePath = vNewValue

??If Right(lImagePath,1) <> "/" Then lImagePath = lImagePath & "/"

?End Property

?'========================================

?

?Private lSelectedNode??'被选择的节点

?Public Property Get SelectedNode()

??Set SelectedNode = lSelectedNode

?End Property

?Public Property Let SelectedNode(ByVal vNewValue)

??'更新之前先去掉原来的节点的边框

??If Not lSelectedNode Is Nothing Then

???With Document.getElementById("txt" & lSelectedNode.Key).style

????.background = ""

???End With

??End If

??Set lSelectedNode = vNewValue

??With Document.getElementById("txt" & lSelectedNode.Key).style

???.background = SelectedBgcolor

??End With

?End Property

?

?Private lMenuNode

?Private lPopupMenu

?

?'===类的析构函数,用于初始化对象==============

?Private Sub Class_Initialize()

??'===初始化树对象

??Document.Write "

"

??'===

??Redim ArrNodes(0)

??Set ArrNodes(0) = Nothing

??name=""

??TreeView_Name = "Efei Super TreeView"

??

??Set lSelectedNode = Nothing

??Set lMenuNode = Nothing

??lPopupMenu = ""

??

??Redim ArrImage(1,2)

??ArrImage(0,0) = "FolderClose"

??ArrImage(1,0) = "FolderClose.gif"

??ArrImage(0,1) = "FolderOpen"

??ArrImage(1,1) = "FolderOpen.gif"

??ArrImage(0,2) = "Rplus"

??ArrImage(1,2) = "Rplus.gif"

??AddImage "root","root.gif"

??AddImage "file","file.gif"

??

??lImagePath = "Image/"

??FirstDisplayLevel = 0

??UseConnectLine = True

??AddFromExpand = False

??Target = "_Blank"

??

??Font_Size = "12px"

??Font_Family = "宋体"

??Font_Color = "#000000"

??SelectedBgcolor = "#D4D0C8"

??

?End Sub

?'===============================================

?

?'===功能:?添加一个节点

?'===参数:?Text???节点显示的文本

?'???Key????节点关键字,该关键字必须唯一

?'???HyperLink??节点要链接到的地址

?'???Node???父节点或者兄弟节点

?'???AddType???添加类型,0-子节点,1-子节点,2-前置节点,3-后置节点

?'???Image???节点的图片,如空,则使用关闭的文件夹

?Public Function add(ByVal Text,ByVal Key,ByVal HyperLink,ByRef Node,ByVal AddType,ByVal Image)

??Dim i

??'先检查关键字是否已存在,参数是否合法

??Key = Trim(Key)

??If Key = "" Then

???Msgbox "关键字不能为空",vbInformation,TreeView_Name

???Exit Function

??End If

??If NOT Me.Nodes(Key) Is Nothing Then

???Msgbox "关键字【" & Key & "】已存在",vbInformation,TreeView_Name

???Exit Function

??End If

??Text = Trim(Text)

??If Text = "" Then

???Msgbox "节点文本不能为空",vbInformation,TreeView_Name

???Exit Function

??End If

??If IsNumeric(AddType) = True Then

???If AddType < 0 And AddType > 3 Then

????AddType = 1

???End If

??Else

???AddType = 1

??End If

??If Node Is Nothing Then

???If Me.NodesCount <> 0 Then

????Msgbox "根节点只能有一个",vbInformation,TreeView_Name

????Exit Function

???End If

???AddType = 0

??End IF

???

??Redim Preserve ArrNodes(Me.NodesCount)

??Set ArrNodes(Ubound(ArrNodes)) = New Node

??

??

??

??With ArrNodes(Ubound(ArrNodes))

???.Key = Key

???.Text=Text

???.HyperLink=HyperLink

???

???.AddType = AddType

???.Image = Image

???Set .parentObject = Me

???

???

???Select Case AddType

????Case 0??'根节点

?????Set .ParentNode=Nothing

?????Set .NextNode = Nothing

????Case 1??'子节点

?????Set .ParentNode = Node??????'父节点

?????If Node.ChildrenCount > 0 Then

??????Set .PreviousNode = Node.Children(Node.ChildrenCount)

??????Set Node.Children(Node.ChildrenCount).NextNode = ArrNodes(Ubound(ArrNodes))

?????End If

?????Set .NextNode = Nothing

????Case 2??'插在前面

?????Set .ParentNode = Node.ParentNode

?????Set .PreviousNode = Node.PreviousNode

?????Set Node.PreviousNode.NextNode = ArrNodes(Ubound(ArrNodes))

?????Set Node.PreviousNode = ArrNodes(Ubound(ArrNodes))

?????Set .NextNode = Node

?????

????Case 3??'插在后面

?????Set .ParentNode = Node.ParentNode

?????Set .PreviousNode = Node

?????Set .NextNode = Node.NextNode

?????Set Node.NextNode = ArrNodes(Ubound(ArrNodes))

???End Select

???If Not .ParentNode Is Nothing Then

????'更新父节点的内容

????.Level = .ParentNode.Level + 1

????

????.ParentNode.AddChild ArrNodes(Ubound(ArrNodes))??'添加子节点

???End If

???'If Image <> "" Then

???'?.Image = Me.Images(Image)

???'End If

???

???.Display

???

???

???If .Level > Me.FirstDisplayLevel Then

????.DisplayStatus = 0

???Else

????If NOT .ParentNode Is Nothing AND AddFromExpand = False Then

?????If .ParentNode.ExpandStatus = 0 Then

??????.ParentNode.ExpandStatus = 1??'自己都显示了,那说明父节点肯定是展开的

?????End If

????End If

????.DisplayStatus = 1

????

???End If

???

???

???

???

???If NOT .ParentNode Is Nothing Then??

????RefreshImage .ParentNode????

???End If

???'=================

??End With

??Set add = ArrNodes(UBound(ArrNodes))

?End Function

?'==============================================================================================

?

?

?'===功能:?移除一个节点,包括该节点下的所有子节点=============================================

?'===参数:?Key???节点的Key,或者是顺序号

?Public Function RemoveNode(ByVal Key)

??Dim i

??Dim Node

??Set Node = Nothing

??Key = Trim(Key)

??If Key = "" Then

???Exit Function

??End IF

??If IsNumeric(Key) = True Then

???If Key > 0 And Key <= Me.NodesCount Then

????Set Node = Nodes(Key)

???End If

??Else

???Set Node = Nodes(Key)

??End If

??If Node Is Nothing Then

???Exit Function

??End If

??Do Until Node.ChildrenCount = 0

???RemoveNode Node.Children(1).Key

??Loop

??

??If Not Node.PreviousNode Is Nothing Then

???'如果有前置节点,则要重新设置前置节点的后置节点

???Set Node.PreviousNode.NextNode = Node.NextNode

??End If

??If Not Node.NextNode Is Nothing Then

???'如果有后置节点,则要重新设置后置节点的前置节点

???Set Node.NextNode.previousNode = Node.PreviousNode

??End If

??

??'===设置它的父节点的子节点内容================================

??With Node.ParentNode

???

???For i = 0 To .ChildrenCount - 1

????If .ChildrenNodes(i).Key = Key Then

?????Exit For

????End If

???Next

???For i = i To .ChildrenCount - 2

????Set .ChildrenNodes(i) = .ChildrenNodes(i+1)

???Next

???.ChildrenCount = .ChildrenCount - 1

???Redim Preserve ChildrenNodes(.ChildrenCount - 1)

??End With

??'=============================================================

??

??'===设置树对象的节点集合======================================

??For i = 0 To Ubound(ArrNodes)

???If ArrNodes(i).Key = Key Then Exit For

??Next

??For i = i To Ubound(ArrNodes) - 1

???Set ArrNodes(i) = ArrNodes(i+1)

??Next

??Redim Preserve ArrNodes(Ubound(ArrNodes)-1)

??'==============================================================??

??

??Set Node = Document.getElementByID(Key).parentElement.parentElement

??Node.ParentElement.parentElement.deleteRow Node.rowIndex

??

??

??

??Set Node = Nothing

?End Function

?'==============================================================================================

?

?

?

?'===Nodes集合,返回一个节点,如果没有,返回Nothing========

?Public Function Nodes(index)

??dim i

??Set Nodes = Nothing

??If IsNumeric(index) = True Then

???If Ubound(ArrNodes)+1 >= index And index > 0 Then

????Set Nodes = ArrNodes(index - 1)

???End If

??Else

???If Ubound(ArrNodes) = 0 And ArrNodes(0) Is Nothing Then

????

???Else

????For i=0 to Ubound(ArrNodes)

?????If ArrNodes(i).Key = index Then

??????Set Nodes = ArrNodes(i)

?????End If

????Next

???End If

??End If

?End Function

?'==========================================================

?

?Public Property Get NodesCount()

??If Ubound(ArrNodes) = 0 And ArrNodes(0) Is Nothing Then

???NodesCount = 0

??Else

???NodesCount = Ubound(ArrNodes) + 1

??End If

?End Property

?Public Property Let NodesCount(ByVal vNewValue)

??Msgbox "NodesCount属性只读!"

?End Property

?

?'===功能:?清空图标集合=====================================

?Public Function ClearAllImage()

??Redim ArrImage(1,0)

?End Function

?'===End======================================================

?

?'===功能:?添加图标集合=====================================

?'???如果关键字imgKey存在,则更新,如不存在,则添加

?'===参数:?imgKey??图标关键字

?'???imgSrc??图标的名称

?Public Function AddImage(ByVal imgKey,ByVal imgFileName)

??dim i

??For i=1 To Ubound(ArrImage,2)

???If ArrImage(0,i) = imgKey Then

????ArrImage(1,i) = imgFileName??'更新

????Exit Function

???End If

??Next

??'添加

??If IsNumeric(imgFileName) = True Then

???Msgbox "图标关键字不能为纯数字!请使用字母或字母和数字的组合。"

???Exit Function

??End If

??i = Ubound(ArrImage,2)+1

??Redim Preserve ArrImage(1,i)

??ArrImage(0,i) = imgKey

??ArrImage(1,i) = imgFileName

?End Function

?'===End======================================================

?

?'

[1] [2] [3] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有