Sort an Arraylist holding an array of a custom class object of Orders

I need to sort an arraylist which holds a array of objects called orders.
Orders has a property called OrderDate and a List Of testCodes.
I want to sort the Araylist in asc OrderDate
here is some code snippet on how the arraylist gets populated

Dim deliveryOrders as New Arraylist
Dim orders as Orders
Dim orders.TestCodes - new List(of testcodes)
order .OrderDate = '3/1/2001'
blah blah blah

deliveryOrders.Add(orders)
 Need to sort this deliveryOrders arraylist
Public Class Order    
    Private _OrderDate As String   
    Private _Tests As List(Of TestCodes)
	
	Public Property CollectionDate() As String
        Get
            Return _CollectionDate
        End Get
        Set(ByVal value As String)
            _CollectionDate = value
        End Set
    End Property
	
    Public Property Tests() As List(Of TestCodes)
        Get
            Return _Tests
        End Get
        Set(ByVal value As List(Of TestCodes))
            _Tests = value
        End Set
    End Property
End Class

Public Class TestCodes
    Private _TestCode As String
    Private _Description As String
   
    Public Property TestCode() As String
        Get
            Return _TestCode
        End Get
        Set(ByVal value As String)
            _TestCode = value
        End Set
    End Property
    Public Property Description() As String
        Get
            Return _Description
        End Get
        Set(ByVal value As String)
            _Description = value
        End Set
    End Property


End Class

Open in new window

LVL 1
countrymeisterAsked:
Who is Participating?
 
countrymeisterAuthor Commented:
Yes I did try deliveryOrders.Sort()
 it gave me the following error, at Least  one object must Implement Icomparable
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
You have a sort method

deliveryOrders.Sort()
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
But you can use SortedList or a SortedDictionary. They are strong typed classes and it will do what you want.

Dim deliveryOrders As New SortedList(Of Integer, Order)
Dim deliveryOrders As New SortedDictionary(Of Integer, Order)
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
countrymeisterAuthor Commented:
I am not clear  on how would it sort on the Orders OrderDate field, there is another field called testodes. What if I add few new fields to the Orders class.

I want to specifically sort on the OrderDate field
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Have you tried?
0
 
countrymeisterAuthor Commented:
Pleaase refund the points as I resolved this issue myself
What was needed was the implementation of the Icomparable and Icomaprer interfaces
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.