Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Programmically Multiple Sort Order in Crystal Report

Posted on 2010-09-16
6
Medium Priority
?
1,131 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

824 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