Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grouping help

Status
Not open for further replies.

infimo

Technical User
Apr 8, 2004
22
US
I am grouping my report using two fields Field A and Field B.

I want the user to be able to either group by Field A and Field B or only by Field A. In both cases I want the details to be sorted on the basis of Field C.

How can this be achieved?

Infimo
 
You can create a parameter that will allow the user to pick which field. The parameter should be String type and the default values should be "Field A and B" and "Field A".

Create a formula that will return the appropriate field(s) based upon what the user picks in teh parameter.

@Dynamic_Group

If {?Param1} = "Field A and B" then
{table.fieldA} & {table.fieldB}
Else
{table.fieldA}

Now you can insert a group based upon the @Dynamic_Group
formula.
Lastly, add Field C to the Record Sort Expert.

~Brian
 
Grouping will place the rows in the group order first, you can subsort the rows by any other column (such as Field C by using Report->Sort Records (this is CR version dependent).

As for changing the grouping, create a parameter to allow the user to select the type of grouping, and then a formula to use as the group:

Creata a parameter:

In the Field Exploere, right click parameters and select new->name it

Slect type string and then choose set default values

In the default values use:

Field A
Field A & B

Save it

Now create a formula such as:

If {?MyParm = "Field A" then
{table.fielda}
else
{table.fielda}+{table.fieldb}

Now use Insert->Group and select the formula you created.

The report will now prompt for which grouping to use.

-k
 
Thanks bdreed35 and synapsevampire. Your solution worked well.

I am using this report under Visual Studio.NET. Is there a way to set the parameter's value using code. I figured out there's a method ReportObject.setparametervalue and it probably does seem to set the value.

But, before I can set the value, the report gets loaded (in the CrystalReportViewer control) and the prompt for the parameter pops in.

So I guess, my problem now is how to prevent loading the report in the CrystalReportViewer unless prompted to do so?

THanks!

infimo
 
yes you can avoid this prompting.

In the code, open the report, assign all the parameters, then send the report off to CrystalReportViewer control.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top