1
votes

I am using Crystal Reports in my web application and it is being loaded dynamically; i.e. it shows only those columns whose entire row is not null. The value of the parameters will be set at runtime.

Eventually the design of the report will be something as follows

param1     param2     param 3      param4
@formula1  @formula2  @formula3    @forumula4 

where param1,param2,... are parameters which shows the column headers and @formula1,@formula2,@formula3 are formula fields which show the detailfields.

The details of @formula1 is as follows

if {?param1}="EventName" Then {dtHealth.EventName}
Else If {?param1}="Location" Then {dtHealth.Location}
Else if {?param1}="CashsafeSerialNo" Then {dtHealth.CashsafeSerialNo}

Here there is a possibility that the param1 could be EventName or Location. I want to set the width of the formula field in crystalreport at runtime; i.e.

if param1="EventName"
    @formula1.width=100px;
else if param1="Location"
    @formula1.width=200px

Any help will be appreciated.

2
why u need this.You can set one default width and assign auto width to true to the control in which you will bind that parameter.Rahul
CanGrow is different and AutoWidth is different.But please tell me why you need this.Rahul
Updated the question.Please check it ..SparAby
This is a good question. I can't tell you how many times I've needed a field to grow by width.pixelmeow
I don't have a copy of Crystal handy to really check, but I believe you can do this using a SELECT statement in the style formula for the column width.Ally

2 Answers

1
votes

I am not sure, But this "Can Grow" option will help you. you can't apply or good to grow width as possible to overwrite the near field. What I suggest give the fixed width, and give can grow option which dynamically expand in height. Which is good.

Other my suggestion is if it is a display as a single row of data. Then make sub-section of detail and put the field into it and in section expert tick the "Keep together"

http://www.accoladepublications.com/Crystal-Reports-Tips-and-Tricks/303-auto-grow-fields.html

http://www.codeproject.com/Questions/105407/How-to-expand-a-field-in-Crystal-Reports

0
votes

I managed to get this working as I wanted:

I am editing a report someone else has made, they had about 21 set columns that were being suppressed if null, I needed a top descriptive column that grew to the size on the non-suppressed fields:

e.g. on the following layout, any of columns b-g might be suppressed:

----------------------------------
| ID |     Dynamic width column  |
---------------------------------
|    | a | b | c | d | e | f | g |
----------------------------------
| 1  | Data -->                  |
----------------------------------
  1. Make sure 'Can grow' is unticked
  2. Make sure 'Keep together' is unticked

Set your dynamic column to be the width of the first cell that you want it to cover, the width formula add to the existing width, it does not set the value explicitly.

Count the number of non-blank columns in the width formula and multiply by the size of your sub-column in twips (1cm=~567 twips) :

NumberVar ColumnCount;

ColumnCount := 0;

If not isnull({Column.TextA}) then
    ColumnCount := ColumnCount + 1 ;
If not isnull({Column.TextB}) then
    ColumnCount := ColumnCount + 1 ;

ColumnCount * 450;

And there you go, you should get a column that expands in width to the size of your not null columns.