Multiple Column Sort in Crystal for .NET 
Author Message
 Multiple Column Sort in Crystal for .NET

Hello All,

I'm looking for a way to sort a report on multiple columns. I have a default
sort (on two columns) on the report. But the user may want to sort the
report on more than 2 columns (eg: 3 columns). I cannot sort on more than 2
columns from the code. Example below:

Dim crFieldDef, crFieldDef1, crFieldDef2 As
CrystalDecisions.CrystalReports.Engine.FieldDefinition

crFieldDef =
rptRollinReport.Database.Tables(0).Fields.Item("request_status_desc")

crFieldDef1 = rptRollinReport.Database.Tables(0).Fields.Item("territory")

crFieldDef2 = rptRollinReport.Database.Tables(0).Fields.Item("vs_ssn")

rptRollinReport.DataDefinition.SortFields.Item(0).Field = crFieldDef

rptRollinReport.DataDefinition.SortFields.Item(0).SortDirection =
CrystalDecisions.[Shared].SortDirection.DescendingOrder

rptRollinReport.DataDefinition.SortFields.Item(1).Field = crFieldDef1

rptRollinReport.DataDefinition.SortFields.Item(1).SortDirection =
CrystalDecisions.[Shared].SortDirection.DescendingOrder

rptRollinReport.DataDefinition.SortFields.Item(2).SortDirection =
CrystalDecisions.[Shared].SortDirection.DescendingOrder

rptRollinReport.DataDefinition.SortFields.Item(2).Field = crFieldDef2

I get the following error at line

rptRollinReport.DataDefinition.SortFields.Item(2).SortDirection =
CrystalDecisions.[Shared].SortDirection.DescendingOrder

 An unhandled exception of type
'CrystalDecisions.CrystalReports.Engine.InvalidArgumentException' occurred
in crystaldecisions.crystalreports.engine.dll

Additional information: Invalid sort number.

Any help will be greatly appreciated.

TIA

Samish



Wed, 24 Aug 2005 01:12:56 GMT  
 Multiple Column Sort in Crystal for .NET
Samish,

I don't know if you every found a solution to you problem, but here is
how I solved the same problem.

myReport.RecordSelectionFormula = "{qryReportStatus.JobID} = " &
iJobID

If Len(strOrderBy) > 0 Then
   Dim crSortField As SortField
   Dim crDatabaseFieldDefinition As DatabaseFieldDefinition
   Dim aSortArray(2) As String
   Dim x As Integer

         aSortArray(0) = "lastname"
         aSortArray(1) = "firstname"
         aSortArray(2) = "companyname"
         'I actually used a Select..Case here.

   For x = 0 To 2
     crDatabaseFieldDefinition = _
           myReport.Database.Tables(0).Fields(aSortArray(x))
     crSortField = myReport.DataDefinition.SortFields(x)
     crSortField.Field = crDatabaseFieldDefinition
   Next

End If

MAKE SURE THE FIELDS YOU SORT BY ARE ALREADY SORT FIELDS IN YOUR
REPORT!

Good Luck,
Jeremy



Sat, 17 Sep 2005 06:18:42 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Sorting fiels in Crystal .NET by code VB .NET

2. Adding or Suppressing Top N Sort in Crystal.Net and VB.net

3. VB.net and crystal reports.net Multiple reports

4. Multiple column sorts with ListView

5. Multiple column sorting of a ListView

6. Sorting On Multiple Columns In Excel

7. Multiple Column Sorts With ListView

8. Need Help Sorting Multiple Columns in MSHFlexgrid

9. Sorting on multiple columns...

10. Sorting variant array on multiple columns

11. Multiple column sort of ListView

12. VB Net's listview column sort optimization

 

 
Powered by phpBB® Forum Software