locked
Crystal Reports 2010 Changing Sort Order RRS feed

  • Question

  • I have a VB.NET 2010 / Crystal Reports 2010 report based on a dataset containing 2 tables, one containing a list of transactions an the other containing a list of customers and associated balance amounts. The report is grouped by customerID. I am attempting to get the report to sort in descending order of customer balance. The code I am using is as follows

          Dim crSortFields As CrystalDecisions.CrystalReports.Engine.SortFields = rptReport.DataDefinition.SortFields
          For Each crSortField As CrystalDecisions.CrystalReports.Engine.SortField In crSortFields
            If crSortField.SortType = CrystalDecisions.[Shared].SortFieldType.GroupSortField Then
              If crSortField.Field.Name = "CustomerID" Then
                If rdbCode.Checked = True Then
                  crSortField.Field = rptReport.Database.Tables("Customers").Fields("Code")
                ElseIf rdbName.Checked = True Then
                  crSortField.Field = rptReport.Database.Tables("Customers").Fields("Name")
                ElseIf rdbBalance.Checked = True Then
                  crSortField.Field = rptReport.Database.Tables("Customers").Fields("Balance")
                  crSortField.SortDirection = CrystalDecisions.[Shared].SortDirection.DescendingOrder
                Else
                  crSortField.Field = rptReport.Database.Tables("Customers").Fields("SortOrder")
                End If
              End If
            End If
          Next

    If the user selects code or name, the sort works fine but if balance is selected, I am trying to set it to sort in descending order and get the error message 'The sort is not defined in the data definition.' If I take out the line to change the sort direction it sorts by balance in ascending order so it is recognising the sort but for some reason won't let me change the order. Any suggestions would be appreciated. Thanks in advance.

    Andy Baker

    Monday, July 25, 2011 10:35 AM

All replies

  • Hi Andy,

    Curious, what happens if you open the Report in the .NET IDE and try to set the order manually?

    Thank you

    Don


    Don Williams
    Monday, July 25, 2011 4:57 PM