G
Gianluca Zangara
Hi, I would override a Windows.Forms.Combobox to have a
MyObjectCollection instead of a ObjectCollection as Items property.
I've try writing this code, but it seems that items are stored somewhere
else (not in Items property). I can add items to collection but when I
try to select an item from the combobox (at runtime) an exception tells
me that there is no such element in Items (litterally it tells me that
"value 0 for index not valid")
what local variable i have to override to make this code fully working?
Public Class FullComboBox
Inherits ComboBox
Private _Items As FullObjectCollection
Public ReadOnly Property Items() As FullObjectCollection
Get
If _Items Is Nothing Then
_Items = New FullObjectCollection(Me)
End If
Return _Items
' Return _Items
End Get
End Property
End Class
Public Class FullObjectCollection
Inherits ComboBox.ObjectCollection
Public Sub New(ByVal owner As ComboBox)
MyBase.New(owner)
End Sub
Public Overloads Sub Add(ByVal ID As String, ByVal val As String)
MyBase.Add(New objectItem(ID, val))
End Sub
Public Overloads Sub Add(ByVal val As Object)
MyBase.Add(New objectItem("", val))
End Sub
Default Public Overloads Property Item(ByVal index As Integer) As
objectItem
Get
Return MyBase.Item(index)
End Get
Set(ByVal value As objectItem)
MyBase.Item(index) = value
End Set
End Property
End Class
Public Class objectItem
Public ID As String
Public val As String
Public Sub New(ByVal _ID As String, ByVal _val As String)
ID = _ID
val = _val
End Sub
Public Overrides Function ToString() As String
Return val
End Function
End Class
thanks in advance
Gianluca Zangara
MyObjectCollection instead of a ObjectCollection as Items property.
I've try writing this code, but it seems that items are stored somewhere
else (not in Items property). I can add items to collection but when I
try to select an item from the combobox (at runtime) an exception tells
me that there is no such element in Items (litterally it tells me that
"value 0 for index not valid")
what local variable i have to override to make this code fully working?
Public Class FullComboBox
Inherits ComboBox
Private _Items As FullObjectCollection
Public ReadOnly Property Items() As FullObjectCollection
Get
If _Items Is Nothing Then
_Items = New FullObjectCollection(Me)
End If
Return _Items
' Return _Items
End Get
End Property
End Class
Public Class FullObjectCollection
Inherits ComboBox.ObjectCollection
Public Sub New(ByVal owner As ComboBox)
MyBase.New(owner)
End Sub
Public Overloads Sub Add(ByVal ID As String, ByVal val As String)
MyBase.Add(New objectItem(ID, val))
End Sub
Public Overloads Sub Add(ByVal val As Object)
MyBase.Add(New objectItem("", val))
End Sub
Default Public Overloads Property Item(ByVal index As Integer) As
objectItem
Get
Return MyBase.Item(index)
End Get
Set(ByVal value As objectItem)
MyBase.Item(index) = value
End Set
End Property
End Class
Public Class objectItem
Public ID As String
Public val As String
Public Sub New(ByVal _ID As String, ByVal _val As String)
ID = _ID
val = _val
End Sub
Public Overrides Function ToString() As String
Return val
End Function
End Class
thanks in advance
Gianluca Zangara