How to make a "List" Property??
Does anybody know how to make a List Property that shows in the property browser like the listbox does? What I want is exactly that, so there is a dropdown and it lets you type stuff to add to the list. I'm NOT TALKING ABOUT AN ENUM!!! So don't suggest that!!! Take a look at the List Property for a listbox before you post. The right answer gets a reward.
[366 byte] By [
WizBang] at [2007-11-17 17:08:43]

# 1 Re: How to make a "List" Property??
The LIST property for COMBO/LISTBOX is just a STRING delimited with vbCRLF. To implement this, you have few ways but here is one that I came up with (have not fully tested this but it should demonstrate the objective)
In a CLASS MODULE (lets call is clsListData)
Dim vList() As Variant
Dim nCurPoint As Long
Private Sub Class_Initialize()
ReDim szList(0)
nCurPoint = 0
End Sub
Public Property Get List(Index As Variant) As Variant
On Error Resume Next
List = vList(Index)
If (Err.Number <> 0) Then
Call Err.Raise(vbObjectError + 1, "Class1::Get-List", "Invalid index")
End If
End Property
Public Property Let List(Index As Variant, ByVal vNewValue As Variant)
On Error Resume Next
vList(Index) = vNewValue
If (Err.Number <> 0) Then
Call Err.Raise(vbObjectError + 1, "Class1::Let-List", "Invalid index")
End If
End Property
Public Sub AddItem(vValue As Variant)
ReDim Preserve vList(nCurPoint)
vList(nCurPoint) = vValue
nCurPoint = nCurPoint + 1
End Sub
Public Sub Clear()
ReDim vList(0)
nCurPoint = 0
End Sub
Public Property Get Count() As Long
Count = UBound(vList)
End Property
To implement:
Sub Main()
Dim oList As New clsListData
Call oList.AddItem("test")
Call oList.AddItem(1)
Call oList.AddItem("email")
MsgBox oList.List(0)
MsgBox oList.List(1)
MsgBox oList.List(2)
' this line will throw and exception - invalid index
MsgBox oList.List(3)
End Sub
Have fun,
-Cool Bizs
# 2 Re: How to make a "List" Property??
Nope, that's not it! I want the thing to show up in the property browser with the dropdown to add items JUST LIKE THE LIST PROPERTY OF A LISTBOX. Adding items at runtime is a piece of cake, but I'm talking about design time.