Solved

Programmically Multiple Sort Order in Crystal Report

Posted on 2010-09-16
6
1,068 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 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
Industry Leaders: 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 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Making exceptions for ValidationAttribute 2 27
c# ftp code 3 35
asp.net, radiobuttonlist, c# 3 39
How to set focus on a dynamic control 18 28
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

730 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