D
Dales
I have a custom class that provides information about training course
history (in-house IT training).
There are numerous course history entries for a student or group of
students, and they're each new'ed up as an objCourseHistory object and
stored in an arraylist.
(Hardcoding examples for illustration purposes, in reality this is
done in a loop and built from external data)
'*************************************
Dim alCourseHistory as New Arraylist
Dim o as New objCourseHistory
With o
o.Course = "Visual Basic .NET"
o.CourseID = 1
o.Series = "DTNET"
o.InstructorID = "12345678"
o.Status = "C"
o.Offering = 5
o.AddDate("01-17-2004")
o.AddDate("01-18-2004")
o.AddDate("01-19-2004")
End With
alCourseHistory.Add(o)
'*************************************
In order to allow this arraylist to be sorted, I have implemented
IComparable and have the following "CompareTo" function:
'*************************************
Class objCourseHistory
Implements IComparable
....
....
Public Function CompareTo(ByVal obj As Object) _
As Integer Implements System.IComparable.CompareTo
If CType(obj, objCourseHistory)._course > Me._course Then
Return -1
Else
Return 0
End If
End Function
'*************************************
This works fine and allows my arraylist of "objCourseHistory" objects
to be sorted on the "Course" value before I display them on the form
by simply doing an arraylist.Sort() where arraylist contains my
objects.
Is there a way to allow this arraylist of objects to be sorted on
DIFFERENT fields as well, or do I get to pick one only and one only?
I'd like to implement my own sorting by clicking header labels and
sorting the arraylist differently then rebuilding the form. I'd like
to take this approach as a datagrid bound to a custom arraylist of
objects doesn't sort and even if I could get it to sort it doesn't
have near the level of customization I need for how I want my data
laid out - so I scrapped the datagrid approach long ago.
If anyone knows how to allow the CompareTo function to sort more than
one way based on an additional parameter (maybe an enumeration value
passed in?), please let me know.
Thanks!
history (in-house IT training).
There are numerous course history entries for a student or group of
students, and they're each new'ed up as an objCourseHistory object and
stored in an arraylist.
(Hardcoding examples for illustration purposes, in reality this is
done in a loop and built from external data)
'*************************************
Dim alCourseHistory as New Arraylist
Dim o as New objCourseHistory
With o
o.Course = "Visual Basic .NET"
o.CourseID = 1
o.Series = "DTNET"
o.InstructorID = "12345678"
o.Status = "C"
o.Offering = 5
o.AddDate("01-17-2004")
o.AddDate("01-18-2004")
o.AddDate("01-19-2004")
End With
alCourseHistory.Add(o)
'*************************************
In order to allow this arraylist to be sorted, I have implemented
IComparable and have the following "CompareTo" function:
'*************************************
Class objCourseHistory
Implements IComparable
....
....
Public Function CompareTo(ByVal obj As Object) _
As Integer Implements System.IComparable.CompareTo
If CType(obj, objCourseHistory)._course > Me._course Then
Return -1
Else
Return 0
End If
End Function
'*************************************
This works fine and allows my arraylist of "objCourseHistory" objects
to be sorted on the "Course" value before I display them on the form
by simply doing an arraylist.Sort() where arraylist contains my
objects.
Is there a way to allow this arraylist of objects to be sorted on
DIFFERENT fields as well, or do I get to pick one only and one only?
I'd like to implement my own sorting by clicking header labels and
sorting the arraylist differently then rebuilding the form. I'd like
to take this approach as a datagrid bound to a custom arraylist of
objects doesn't sort and even if I could get it to sort it doesn't
have near the level of customization I need for how I want my data
laid out - so I scrapped the datagrid approach long ago.
If anyone knows how to allow the CompareTo function to sort more than
one way based on an additional parameter (maybe an enumeration value
passed in?), please let me know.
Thanks!