Active Reports 6 – Sort a collection in Active Reports

In this example, we take an unsorted Product Collection called ProductCollection that is assigned

to our report Data Source. We instantiate another Product Collection for sorting called

sortedProductCollection. Using a Do Loop, we read the Product Collection and build the

sortedProductCollection in sorted order. When done, we overlay the ProductCollection

in the Data Source with our sortedProductCollection

‘Sort the Product Collection

Dim sortedProductCollection As New ProductCollection

‘A class that defines a collection

Dim mCounter = 0
Dim mLoopComplete = False

Do Until mLoopComplete = True
    For Each item As product In rpt.DataSource(0).ProductCollection
        If item.product_number.Value = mCounter + 1 Then
            Exit For
        End If
    mCounter += 1
    If rpt.DataSource(0).ProductCollection.Count = sortedProductCollection.Count Then
       mLoopComplete = True
    End If

rpt.DataSource(0).ProductCollection = sortedProductCollection
Please follow and like us: