How to change report field alignment in a crystal repository at run time

In the crystal report, I want to set the field alignment accordingly. How can I do the same at runtime?


It's good. It works. Thanks. I did the same and the code is shown below.

var fo = rpt.ReportDefinition.ReportObjects["InvoiceComment"]; fo.ObjectFormat.HorizontalAlignment = Alignment.LeftAlign; if (ds.Tables[0].Rows[0].ItemArray[19].ToString() == "Right") fo.ObjectFormat.HorizontalAlignment = Alignment.RightAlign; else if (ds.Tables[0].Rows[0].ItemArray[19].ToString() == "Center") fo.ObjectFormat.HorizontalAlignment = Alignment.HorizontalCenterAlign;` 

But now I'm experiencing another problem.

 FieldObject fo = rpt.ReportDefinition.ReportObjects["InvoiceComment"] as FieldObject; 

OR

 var fo = rpt.ReportDefinition.ReportObjects["InvCom"]; 

Show the same error "Index was outside the array." And if I use different code instead, it works.

 FieldObject fo = rpt.ReportDefinition.ReportObjects[35] as FieldObject; 

How to encrypt it. Thanks at Advance.

+4
source share
3 answers

To change the horizontal alignment of a field, follow these steps:

1) Right-click on the field.

2) Select the "Field format" option.

3) Select the "General" tab.

4) Click the formula editor before the horizontal setting and add the desired setting.

5) The following are alignment constants:

Constant

 crDefaultHorAligned crLeftAligned crRightAligned crCenteredHorizontally crJustified 

use it according to your criteria.

+3
source

in C #:

 var field = report.ReportDefinition.ReportObjects["Description1"]; field.ObjectFormat.HorizontalAlignment = Alignment.Justified; 

Possible options:

 namespace CrystalDecisions.Shared { public enum Alignment { DefaultAlign, LeftAlign, HorizontalCenterAlign, RightAlign, Justified, Decimal, } } 
0
source

I used RTF Text interpretation and set the value to formatted text, and my problem is resolved ... I developed a better crystal report using RTF.

0
source

All Articles