Message 1 of 5
Swap Index of Items in a Collection

Not applicable
09-29-2004
12:50 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have created a collection class with the code below and fill it with
objects from another class. I have populated a listbox with the
MyObject.Name property of these objects. What I would like to do now is
swap the positions of the items in the collection and then repopulate the
listbox. Is it possible to change the index of items in a collection?
Thanks for any help.
Chris
Option Explicit
Private m_colColumns As Collection
Private m_lngKeyNum As Long
Public Property Get Count() As Long
Count = m_colColumns.Count
End Property
Public Sub AddColumn(ByRef objColumn As clsColumn)
On Error GoTo AddColumnError
m_colColumns.Add objColumn, CStr(m_lngKeyNum) 'objColumn.Name
m_lngKeyNum = m_lngKeyNum + 1
Exit Sub
AddColumnError:
If Err.Number = 457 Then
MsgBox objColumn.Name & " already exists and was not added. Enter
another name."
Else
MsgBox objColumn.Name & " already exists and was not added."
End If
End Sub
Public Function Item(ByVal v_vntIndex As Variant) As clsColumn
On Error Resume Next
Set Item = m_colColumns.Item(v_vntIndex)
If Err.Number <> 0 Then
Set Item = Nothing
End If
End Function
Public Sub Remove(Index As Variant)
m_colColumns.Remove (Index)
End Sub
Private Sub Class_Initialize()
Set m_colColumns = New Collection
m_lngKeyNum = 1
End Sub
Private Sub Class_Terminate()
Set m_colColumns = Nothing
End Sub
Public Property Get NewEnum() As IUnknown
Set NewEnum = m_colColumns.[_NewEnum]
End Property