I've got the same problem here. I've been looking into doing the same thing and haven't found any solutuions. I've got 3 different fields that I want the user to be able to sort by. I also would like them to have the option of entering a parameter to limit the results displayed. Of course this can all be easily done during design time with 'TopN/Sort Group Expert', but how do you sort a Sum field during runtime.
I've tried using sort fields but I can't get beyond an "Invalid field name" error.
Dim crSortField As SortField
Dim fieldDef As DatabaseFieldDefinition
For Each crSortField In crReportDocument.DataDefinition.SortFields
If crSortField.Field.Name.ToString = strField Then
fieldDef = crReportDocument.Database.Tables(0).Fields(crSortField.Field.Name.ToString) 'where error occurs
crSortField = crReportDocument.DataDefinition.SortFields(0)
crSortField.Field = fieldDef
crSortField.SortDirection = SortDirection.DescendingOrder
Else
'used for debuging
Label1.Text += " " & crSortField.Field.Name.ToString & ", "
End If
Next