P
Paul Nations
I've got arraylists of simple classes bound to controls. I need to search
through those arraylists to set the correct SelectedItem in the control.
The code looks like:
Public Class DegreeMaintenance
Private arrCipCodes As New ArrayList
'populate reader with data
With rdr
Do While .Read
arrCipCodes.Add(New CipCode(.GetString(0), .GetString(1)))
Loop
.Close()
End With
arrCipCodes.Sort()
Public ReadOnly Property CipCodes() As ArrayList
Get
Return arrCipCodes
End Get
End Property
End Class
'*****************************************************************
Public Class CipCode
Private myCipDisplay As String
Private myCipCode As String
Public Sub New(ByVal strCipDisplay As String, ByVal strCipCode As
String)
MyBase.new()
With Me
.myCipDisplay = strCipDisplay 'e.g. 01.9999 Agriculture,
Agriculture Operations and Related Sciences, Other
.myCipCode = strCipCode 'e.g. 01.9999
End With
End Sub
Public ReadOnly Property CipDisplay() As String
Get
Return myCipDisplay
End Get
End Property
Public ReadOnly Property CipCode() As String
Get
Return myCipCode
End Get
End Property
End Class
'****************************************************************
And finally in a form is this code:
'
Me.cbCipCode.SelectedIndex =
DegreeMaintenance.CipCodes.BinarySearch(dd.CipDisplay)
When I execute this line I get this message:
Additional information: Specified IComparer threw an exception.
I'm not sure where to go from here. Do I need to implement an IComparer?
How do I search on the second element of the class members of my arraylist?
through those arraylists to set the correct SelectedItem in the control.
The code looks like:
Public Class DegreeMaintenance
Private arrCipCodes As New ArrayList
'populate reader with data
With rdr
Do While .Read
arrCipCodes.Add(New CipCode(.GetString(0), .GetString(1)))
Loop
.Close()
End With
arrCipCodes.Sort()
Public ReadOnly Property CipCodes() As ArrayList
Get
Return arrCipCodes
End Get
End Property
End Class
'*****************************************************************
Public Class CipCode
Private myCipDisplay As String
Private myCipCode As String
Public Sub New(ByVal strCipDisplay As String, ByVal strCipCode As
String)
MyBase.new()
With Me
.myCipDisplay = strCipDisplay 'e.g. 01.9999 Agriculture,
Agriculture Operations and Related Sciences, Other
.myCipCode = strCipCode 'e.g. 01.9999
End With
End Sub
Public ReadOnly Property CipDisplay() As String
Get
Return myCipDisplay
End Get
End Property
Public ReadOnly Property CipCode() As String
Get
Return myCipCode
End Get
End Property
End Class
'****************************************************************
And finally in a form is this code:
'
Me.cbCipCode.SelectedIndex =
DegreeMaintenance.CipCodes.BinarySearch(dd.CipDisplay)
When I execute this line I get this message:
Additional information: Specified IComparer threw an exception.
I'm not sure where to go from here. Do I need to implement an IComparer?
How do I search on the second element of the class members of my arraylist?