Dynamic Positioning (Crystal Reports – 2008)
For the below requirement,
i) Where there are 5 columns to be placed at Header Section of the report dynamically.
ii) All of these 5 columns need to have a dynamic position, so as in case if any of the field is null then no virtual space is occupied by the same column.
iii) Also other columns need to have their horizontal position set dynamically depending on the existence of other columns.
Solution
Let us say that we have 5 columns from Information Table which are required to be displayed in the following sequence
1) Name
2) City
3) State
4) Country
5) Product
In order to set the dynamic position for the above fields we would be required to follow the below steps:-
1) Place all the fields at the header section one above another and let all the fields have fixed height and variable width as per requirement.
2) Right click on the above placed fields one by one and select Size and Position option.
3) Set the X –axis value conditionally as below
A) For Field City :
Numbervar Position;
Position: = 0;
If isnull ({information. Name}) then
Position: = Position
Else
Position: = (2.9 + .2) * 567;
If isnull ({information. City}) then
0
Else
Position;
B) For Field State:
Numbervar Position;
Position: = 0;
If isnull ({information. Name}) then
Position: = Position
Else
Position: = (2.9 + .2) * 567;
If isnull ({information. City}) then
Position: = Position
Else
Position: = ((2.5 + .2) * 567) + Position;
If isnull ({information. State}) then
0
Else
Position;
C) For Field Country:
Numbervar Position;
Position: = 0;
If isnull ({information. Name}) then
Position: = Position
Else
Position: = (2.9 + .2) * 567;
If isnull({information. City}) then
Position: = Position
Else
Position: = ((2.5 + .2) * 567) + Position;
If isnull ({information. State}) then
Position: = Position
Else
Position: = ((2 + .2) * 567) + Position;
If isnull ({information. Country}) then
0
Else
Position;
D) For Field Product:
Numbervar Position;
Position: = 0;
If isnull ({information. Name}) then
Position: = Position
Else
Position: = (2.9 + .2) * 567;
If isnull ({information. City}) then
Position: = Position
Else
Position: = ((2.5 + .2) * 567) + Position;
If isnull ({information. State}) then
Position: = Position
Else
Position: = ((2 + .2) * 567) + Position;
If isnull ({information. Country}) then
Position: = Position
Else
Position: = ((2.5 + .2) * 567) + Position;
If isnull ({information. Product}) then
0
Else
Position;
Result
Case 1:- When none of the below fields are null
Name City State Country Product
Case 2:- When City field is null
Name State Country Product
Case 3:- When State field is null
Name City Country Product
Case 4:- When Country field is null
Name City State Product
Case 5:- When Product field is null
Name City State Country
Case 6:- When Name field is null
City State Country Product
Note: - With the above implementation at the Report level we would achieve the dynamic placement of fields, with fields which are null would be replaced by their adjacent fields which are not null.