Solved

Programmically Multiple Sort Order in Crystal Report

Posted on 2010-09-16
6
1,054 Views
Last Modified: 2012-05-10
Hi

I am trying to programmically sort my crystal report on multiple columns.
I am able to sort one column by the below code.

 FieldDefinition fd;
fd = cryRpt.Database.Tables[0].Fields[_sortfield];
cryRpt.DataDefinition.SortFields[0].Field = fd;
cryRpt.DataDefinition.SortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder;

where _sortfield is determined by the users selecting a sorting field.

However, how can I implement a multiple order column sort where a user can select multiple columns?

My information comes from a dataset created from multiple tables so cannot use SQL to sort my datatable.

Thanks.
0
Comment
Question by:elmbrook
  • 3
  • 3
6 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 33697261
Use a similar method to add other columns

cryRpt.DataDefinition.SortFields[1].Field = fd;
cryRpt.DataDefinition.SortFields[1].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder;

Another way is to use formulas in the report for the sorting and change them through code

mlmcc
0
 

Author Comment

by:elmbrook
ID: 33697320
If I run the below code I get an error 'The sorting already exists'
     
           FieldDefinition fd;
                fd = cryRpt.Database.Tables[0].Fields["Memno"];
                cryRpt.DataDefinition.SortFields[0].Field = fd;
                cryRpt.DataDefinition.SortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder;
               
                FieldDefinition fd1;
                fd1 = cryRpt.Database.Tables[0].Fields[_sortfield];
                cryRpt.DataDefinition.SortFields[1].Field = fd;
                cryRpt.DataDefinition.SortFields[1].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder;
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 33759531
Is it a typo or did you mean to use fd1 for the second sort.

mlmcc
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:elmbrook
ID: 33765519
no is not a typo.

How do I define another a second sort field?
I am relatively new to Crystal Reports and am struggling to get the report sorted on multiple columns.
In the end I have gone with 3 different reports for each selection possible.

I would still like to use a multiple column sort option if there is a solution.
not sure how to implement your code?
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 33766738
You defined fd1 then used fd when you assigned the sort field thus assigning the field twice.

The second one should be


                FieldDefinition fd1;
                fd1 = cryRpt.Database.Tables[0].Fields[_sortfield];
                cryRpt.DataDefinition.SortFields[1].Field = fd1;
                cryRpt.DataDefinition.SortFields[1].SortDirection = CrystalDecisions.Shared.SortDirection.DescendingOrder;

mlmcc
0
 

Author Closing Comment

by:elmbrook
ID: 33773818
duhhh

My bad...

Thanks
0

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 45
InputLanguage 1 27
Need to start a web service from Visual Studio 2015 Pro 2 25
VB.NET 2008 - SQL Timeout 9 26
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question