www.pudn.com > ListViewTreeView.rar > cls_Node.cls
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "cls_Node"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' **********************************************************************
' 描 述:在listbox中实现treeview数效果
' Play78.com : 网站导航,源码之家,绝对开源
' 海阔天空收集整理
' 网址:http://www.play78.com/
' QQ:13355575
' e-mail:hglai@eyou.com
' 编写日期:2005年07月28日
' **********************************************************************
Option Explicit
Public Key As String
Public Description As String
Public Value As String
Public IsExpanded As Boolean
Public NextSibling As cls_Node
Public FirstChild As cls_Node
Public Parent As cls_Node
Public ListIndex As Long
'
'
'
Public Sub AddChild(ByRef NewChild As cls_Node)
Set NewChild.Parent = Me
If FirstChild Is Nothing Then
Set FirstChild = NewChild
Else
If NewChild.Description < FirstChild.Description Then
Set NewChild.NextSibling = FirstChild
Set FirstChild = NewChild
Else
Dim InsertAfter As cls_Node: Set InsertAfter = FirstChild
Do
If NewChild.Description > InsertAfter.Description Then
If InsertAfter.NextSibling Is Nothing Then Exit Do
If InsertAfter.NextSibling.Description > NewChild.Description Then Exit Do
End If
If InsertAfter.NextSibling Is Nothing Then Exit Do
Set InsertAfter = InsertAfter.NextSibling
Loop
Set NewChild.NextSibling = InsertAfter.NextSibling
Set InsertAfter.NextSibling = NewChild
End If
End If
End Sub
'
'
'
Public Function FindByKey(ByVal Key As String) As cls_Node
If Me.Key = Key Then Set FindByKey = Me: Exit Function
Dim SeekInto As cls_Node
Set SeekInto = Me.FirstChild
While Not SeekInto Is Nothing
If SeekInto.Key = Key Then Set FindByKey = SeekInto: Exit Function
Set FindByKey = SeekInto.FindByKey(Key): If Not FindByKey Is Nothing Then Exit Function
Set SeekInto = SeekInto.NextSibling
Wend
End Function
'
'
'
Public Function FindFirst(ByVal Desc As String) As cls_Node
If InStr(UCase(Me.Description), UCase(Desc)) = 1 Then Set FindFirst = Me: Exit Function
Dim SeekInto As cls_Node
Set SeekInto = Me.FirstChild
While Not SeekInto Is Nothing
If SeekInto.Key = Key Then Set FindFirst = SeekInto: Exit Function
Set FindFirst = SeekInto.FindFirst(Desc): If Not FindFirst Is Nothing Then Exit Function
Set SeekInto = SeekInto.NextSibling
Wend
End Function
'
'
'
Public Sub EnsureVisible()
Dim nod As cls_Node
Set nod = Me.Parent
While Not nod Is Nothing
nod.IsExpanded = True
Set nod = nod.Parent
Wend
End Sub
'
'
'
Private Sub Class_Terminate()
Set NextSibling = Nothing
Set Parent = Nothing
Set FirstChild = Nothing
End Sub