Link to home
Start Free TrialLog in
Avatar of countrymeister
countrymeister

asked on

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

Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

You have a sort method

deliveryOrders.Sort()
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)
SOLUTION
Avatar of countrymeister
countrymeister

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Have you tried?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of countrymeister
countrymeister

ASKER

Pleaase refund the points as I resolved this issue myself
What was needed was the implementation of the Icomparable and Icomaprer interfaces