Solved

Programmically Multiple Sort Order in Crystal Report

Posted on 2010-09-16
6
1,083 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 101

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 101

Expert Comment

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

mlmcc
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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 101

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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