Solved

Programmically Multiple Sort Order in Crystal Report

Posted on 2010-09-16
6
1,042 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now