cancel
Showing results for 
Search instead for 
Did you mean: 

ReportDocument object, sort options

Former Member
0 Kudos

I am using Visual Studio 2005, Visual Basic syntax, SqlServer 2000 and CrystalReports XI to build a Windows Forms application. I have a form that allows the user to define criteria for a report which I pass as a parameter to a ReportDocument object. I now want to allow the users to define the sort fields also. But it appears that the sort fields of the object are readonly. Can I define the sort fields of the ReportDocument class in my code?

Accepted Solutions (1)

Accepted Solutions (1)

former_member184995
Active Contributor
0 Kudos

Hi Connie,

There should be a sort field sample in the following samples package:

[http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_web_samples.exe.asp]

Also, make sure you are using Crystal Reports XI Release 2 (11.5.xxx) with VS.NET 2005 and not Crystal Reports XI (11.0.xx) since XI is not supported with .NET 2005.

Good luck,

Jason

Former Member
0 Kudos

Well, I thought my question was answered. It was a very good example. But.... I want to allow the users to select more than 1 field to sort by. I have created the following function and it works if I only have 1 item, but it fails on the 2nd item if I have more than 1. Can you sort by more than 1 item? And also, it is breaking to a new page for every new last name (my sort), is there a property I need to set so it does not do that? Thanks for your help.

Private Function lfSort(Byval pSortList As List(Of Miscellaneous3))

'pSortList contains a list of fields that the user wants this report to be sorted by

'the list contains 3 items: 1)Code=the field name as defined in the table 2)Display1=the field name in English, not geek talk 3)Display2=the sort order

Dim lSortFld As String

Dim lSortDir As String

Dim crDatabaseFieldDefinition As DatabaseFieldDefinition

Dim crSortField As SortField

If pSortList.Count > 0 Then

For i As Integer = 0 To pSortList.Count - 1

lSortFld = pSortList(i).Code

If pSortList(i).Display2 = "Desc" Then

lSortDir = SortDirection.DescendingOrder

Else

lSortDir = SortDirection.AscendingOrder

End If

'set the crystal parameters

crDatabaseFieldDefinition = crReportDocument.Database.Tables(0).Fields(lSortFld.ToString)

crSortField = crReportDocument.DataDefinition.SortFields(i)

crSortField.Field = crDatabaseFieldDefinition

crSortField.SortDirection = lSortDir

Next

End If

End Function

Former Member
0 Kudos

Well, I thought I had found part of the solution. I added "crSortField.SortType = SortFieldType.RecordSortField" to the loop but it says that it is a readonly property. I was trying to fix the problem with the report breaking to a new page.

Former Member
0 Kudos

Still haven't figured out how to add additional sort fields. All the examples only access the first item in SortFields. Any suggestions?

former_member184995
Active Contributor
0 Kudos

Hi Connie,

I am not entirely sure it is possible. I am unavailable for the next few days and won't be able to try it out. Hopefully on of the other .NET folks will be able to verify if it is possible or not.

Good luck!

Jason

Answers (0)