VB5, VB6Retrieve List Elements
' This is the function that 
' retrieves the elements

Private Function GetItem(ByVal _
   Index As Long) As String
   If OnDemandMode Then
      If m_Parent Is Nothing Then
         ' event-based interface
         Dim result As String
         RaiseEvent GetItem(Index, _
            result)
         GetItem = result
      Else
         ' ISuperListBoxEvent 
         ' custom interface
         GetItem = _ 
            m_Parent.GetItem(Index, m_ID)
      End If
   Else
      ' standard AddItem method
      GetItem = Items(Index)
   End If
End Function

Listing 1 The SuperListBox control invokes this private procedure internally once for each element that must be displayed in its list portion. If the OnDemandMode Boolean variable is False, then the control can retrieve the element from its private Items() array of strings. If OnDemandMode is True and an object has been passed to the SetOwner method (and stored in the m_Parent variable), then the control asks for the element through the GetItem method of the ISuperListBox-Event interface. Finally, if on-demand loading is active but the SetOwner method hasn't been called, the control merely raises a GetItem event in its container form.