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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rearrange fields after hiding some columns

Status
Not open for further replies.

samson123

Programmer
Jun 17, 2005
79
US
I need to dynamically hide and show columns.I am able to achieve that. My problem is I do not understand how to eliminate the space between the columns/ rearrange the fields.

For example.
If the report has 4 columns

Col1 Col2 Col3 Col4

I hide Col2 and Col3, the report appears

Col1 Col4

But I need

Col1 Col4

How to accomplish this ? I tried "Can Grow", but it did not work ?
 
You can either place all possible combinations of fields in different detail sections and then conditionally suppress each section, or you can use parameters to determine which field is in which column so that they are always populated from the left.

-LB
 
Lbass,

Thanks for your quick response.. I am fairly new to Crystal reports...

How do I use parameters option ?

I was looking at other approaches too. I saw "X Position Adjustment" and "Width Adjustment" in the formula workshop..Will these help me to solve my problem....?
 
There might be a way of using the position, but I'm not familiar with it. For the parameter approach, see thread149-655589.

-LB
 
LB,

Thanks for the link.. I will try out and let you know...

Thanks again

 
Parameter approach:

should I be passing the parameters thru VB

Say for example if user select col1 and col4,

Report.ParameterFields.GetItemByName("Param1").AddCurrentValue col1

Report.ParameterFields.GetItemByName("Param2").AddCurrentValue col4


Then Crystal Report will hold these in ?Param1 and ?Param2 fields.

and the formula

@col1
@col2 will probably work based on what I pass....

So I should get

Col1 Col4

Originally I was assigning values in the Parameter window in CR.

Let me know if I am thinking correctly.
 
I know nothing about VB, so cannot really answer your question. My original suggestion was based on working entirely in CR.

-LB
 
Hi samson,
Even we had a similar problem. Though lbass's soln of having all possible combinations of detail sections is a very good one but may not be feasible practically for a few cases.
I am yet to understand his parameters soln.

Instead what we did is shift the remaining columns programatically i.e in your example, shift Col4 to the left to the position where Col2 was originally. We did this by storing the "Left" value of Col2 and setting that value to the "Left" property of Col4.
You may need to use arrays.

Regards,
Manish
 
Hey Manish,

Thanks for taking time to explain.. Your approach is good too..
I was able to fix my problem thru parameters' approach.

I will explain how I accomplished it. I thank LBass for giving me the direction.

************************
Suppose we have the following fields

Customer Product Sale_Date Amount

Assuming user selects 2 fields out of 4 fields, say Customer and Sale_Date and does not select Product and Amount

so output should be

Customer Sale_Date (no spaces) and not like as shown below

Customer Sale_Date


1)In the crystal reports I created 4 parameters
Param1, Param2, Param3, Param4 of Type string. I set the default value for the parameters to a single space " ". Did not include the double quotes.

2)In Vb wrote the following

report.parameterfields.getitemname("Param1").addcurrentvalue "Customer"
report.parameterfields.getitemname("Param2").addcurrentvalue "Sale_Date"

3) In the crystal reports create 4 formulas

//@formula1
Select {?Param1}
Case "Customer":{table.Customer_Name}
Case "Product" :{table.Product_Name}
Case "Sale_Date" :totext({table.Product_Name},"MM/dd/yyyy")
Case "Amount" : totext({table.Amount},2)
default: ""

Just repeated this in the other formulas with different param#. Put the formulas in the detail section. Put {?Param#} in the header section. Suppress column header, db fields

This just works perfect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top