469,086 Members | 1,238 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,086 developers. It's quick & easy.

System.ArgumentOutOfRangeException occurred in system.windows.forms.dll

Dear all,

I've got a problem with my custom combo box.
When I select an entry from it, then I get the error message:

"An unhandled exception of type 'System.ArgumentOutOfRangeException'
occurred in system.windows.forms.dll

Additional information: Specified argument was out of the range of valid
values."

Could you help me to get it running?

Thanks in advance for your help!

Best Regards,

HKSHK

Source Code follows:

Public Class HKSCBObjectCollection
Inherits System.Windows.Forms.ComboBox.ObjectCollection

Dim vItemData() As Long

#Region "Constructor"
Public Sub New(ByVal owner As System.Windows.Forms.ComboBox)
MyBase.New(owner)
End Sub
#End Region

#Region "Add and Insert"
Public Shadows Function Add(ByVal Item As Object) As Integer
Return Add(Item, 0)
End Function
Public Shadows Function Add(ByVal Item As Object, ByVal ItemData As Long)
Dim t% = MyBase.Add(Item)
ReDim vItemData(t%)
vItemData(t%) = ItemData
Return t%
End Function

Public Shadows Sub Insert(ByVal Index As Integer, ByVal Item As Object)
Insert(Index, Item, 0)
End Sub
Public Shadows Sub Insert(ByVal Index As Integer, ByVal Item As Object,
ByVal ItemData As Long)
Dim t%
If Index > -1 And Index < Me.Count + 1 Then
If Index = UBound(vItemData) + 1 Then
Add(Item, ItemData)
Else
MyBase.Insert(Index, Item)
ReDim Preserve vItemData(Index + 1)
For t% = UBound(vItemData) To Index + 1 Step -1
vItemData(t%) = vItemData(t% - 1)
Next
vItemData(Index) = ItemData
End If
End If
End Sub
#End Region

Private Sub CheckItemData()
Dim t%, t1%
t1% = UBound(vItemData)
If t1% <> Me.Count Then
ReDim Preserve vItemData(Me.Count - 1)
End If
End Sub

Public Property ItemData(ByVal Index As Integer) As Long
Get
CheckItemData()
Return vItemData(Index)
End Get
Set(ByVal Value As Long)
vItemData(Index) = Value
End Set
End Property

#Region "Remove, RemoveAt and Clear"
Public Shadows Function Remove(ByVal Item As Object) As Integer
Dim t%
For t% = 0 To Me.Count - 1
If Me.Item(t%) = Item Then
RemoveAt(t%)
Return t%
Exit For
End If
Next
End Function

Public Shadows Sub RemoveAt(ByVal Index As Integer)
Dim t%, t1%
If Index > -1 Then
MyBase.RemoveAt(Index)
t1% = UBound(vItemData)
If Index < t1% Then
For t% = Index To t1% - 1
vItemData(t%) = vItemData(t% + 1)
Next
End If
ReDim Preserve vItemData(Index - 1)
End If
End Sub

Public Shadows Sub Clear()
MyBase.Clear()
ReDim vItemData(-1)
End Sub
#End Region

End Class

Public Class Testbox
Inherits System.Windows.Forms.ComboBox
Private vItems As New HKSCBObjectCollection(Me)
Private vToolTip As New System.Windows.Forms.ToolTip

Public Shadows ReadOnly Property Items() As HKSCBObjectCollection
Get
Return vItems
End Get
End Property

Protected Overrides Sub RefreshItem(ByVal index As Integer)
MyBase.RefreshItem(index)
End Sub

Protected Overrides Sub SetItemsCore(ByVal items As
System.Collections.IList)
MyBase.SetItemsCore(items)
End Sub
End Class
Jun 16 '06 #1
0 3012

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Terrence | last post: by
11 posts views Thread by Andreas Wirén | last post: by
5 posts views Thread by Henry Stock | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.