Print Page | Close Window

Grouping Records at Runtime

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Tips and Tricks
Forum Discription: Have you learned some great tricks to share with the group? Post them here!
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=4208
Printed Date: 01 May 2024 at 7:31pm


Topic: Grouping Records at Runtime
Posted By: Naveed88
Subject: Grouping Records at Runtime
Date Posted: 10 Sep 2008 at 12:10am
ConfusedConfusedHello every body!!!!

i m Developing a website that requires few but strong reporting (Fully Customized). Here i m using Visual Studio 2005 and it's Crystal report tools

What i want is to Group the records by Selected Field in Option(Radio) Button

for Example this is Data Table

ID    Color     Clarity    Carat

1       D            FL          2.0

2        F            VS1       1.4

3        E          VS2        2.0

      D           VS2       2.0

5        D          FL          1.4

 -=- And

  • Color
  • Clarity
  • Carat

are three options and if i select Color

then record should be Grouped by Color

ID     Color     Clarity    Carat

1        D            FL          2.0

      D         VS2         2.0

5        D          FL           1.4

3        E          VS2         2.0

2        F           VS1        1.4

Similarly for  Clarity and Carat fields

 

Please Help me 

Thanks in Advance



-------------
Regards....
Naveed Anjum 9867374437
web Developer
Mumbai,INDIA.



Replies:
Posted By: wjzabs
Date Posted: 17 Mar 2009 at 5:16am

From your example, I am not sure that you are talking about sorting or grouping, because you are saying "grouping" but your example data shows "sorting".

I also don't know how you are planning to get the results of the user's selection of the desired sort from the radio button into the report.  I will assume that you will use a crystal report parameter, and pass the user's sort preference into the report via a parameter from the VB/C# environment or by having the Crystal Report prompt for this parameter value at runtime. 
 
In either case, I think you can get what you are looking for by adding a string formula field that yields the color, clarity, or carat of the detail record using an "if" statement:
 
if {?opt} = 0 then {TABLE_NAME.Color}
else
if {?opt} = 1 then {TABLE_NAME.Clarity}
else
if {?opt} = 2 then ToText({TABLE_NAME.Carat},"###.00")
else
"?"
 
Then, you can sort or group by this new field.
 
The masking on the Carat field is necessary so that a value of 10 will come after a value if 2.0.  With a field like Carat, maybe you won't see this issue (because > 9 Carats may not occur in your data), but I think you can see the issue - also make sure you have enough #'s, or else 1000 will appear before 200.  If you don't want to guess, you can implement 2 formula fields, one a string and the other a decimal value, and use both to create the groups or sort sequence.
 
Also - when creating formulas, pay attention to EvaluationTime  - I generally use WhilePrintingRecords for all of my formulas, but I do not believe you will need that in this one.



Print Page | Close Window