vbAccelerator - Contents of code file: cListBoxStorageClass.clsVERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "cListBoxStorageClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' ==========================================================
' Storing Objects against a controls ItemData or Tag
' property.
'
' This class shows how to store objects against a ListBox
' itemdata using standard techniques, i.e. the Collection
' object.
'
' Copyright 1999 Steve McMahon
' steve@vbaccelerator.com
'
' ----------------------------------------------------------
' vbAccelerator - advanced, free source code:
' http://vbAccelerator.com/
' ==========================================================
Private m_lstThis As ListBox
Private m_c As Collection
Private m_lID As Long
Public Sub Clear()
Set m_c = Nothing
m_lstThis.Clear
Set m_c = New Collection
End Sub
Public Sub Initialise(lstThis As ListBox)
Set m_lstThis = lstThis
End Sub
Public Sub RemoveItem(ByVal lItemIndex As Long)
Dim lID As Long
lID = m_lstThis.ItemData(lItemIndex)
If lID <> 0 Then
m_c.Remove "C" & lID
End If
m_lstThis.RemoveItem lItemIndex
End Sub
Public Property Let ItemData(ByVal lItemIndex As Long, ByRef cData As
cListBoxItem)
Dim lID As Long
lID = m_lstThis.ItemData(lItemIndex)
If lID = 0 Then
lID = Sequence()
m_lstThis.ItemData(lItemIndex) = lID
Else
m_c.Remove "C" & lID
End If
m_c.Add cData, "C" & lID
End Property
Public Property Get ItemData(ByVal lItemIndex As Long) As cListBoxItem
Dim lID As Long
lID = m_lstThis.ItemData(lItemIndex)
If lID <> 0 Then
Set ItemData = m_c.Item("C" & lID)
End If
End Property
Private Property Get Sequence() As Long
m_lID = m_lID + 1
Sequence = m_lID
If m_lID = 2147483647# Then
' wrap. won't always work..
m_lID = -2147483648#
End If
End Property
Private Sub Class_Initialize()
'-2,147,483,648 to 2,147,483,647
m_lID = -2147483648#
Set m_c = New Collection
End Sub
|
|