cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing individual elements of a textobject

0 Kudos

Hi,

I'm using Crystal Reports 2008 in a .Net application.

I'm looping through each object in the report and applying colours at run time. We have certain text headings, fields, borders etc use use a single colour. We want to be able to change that colour without having to touch the individual reports.

So, the general approach is that if the object's font is not black then replace the colour with the new colour.

foreach (Crystal.ReportObject oO in oCurrentReport.ReportDefinition.ReportObjects)

{

if (oO is CrystalDecisions.CrystalReports.Engine.LineObject)

     {

          ...

     }

else if ((oO is CrystalDecisions.CrystalReports.Engine.TextObject))

     {

          ...

     }

}                      

This works fine for most objects but doesn't work for certain textobjects with multiple fonts:

[{@ReferenceHeading}: {@Ref}]

{@ReferenceHeading}: is specified to have a colour.

{@Ref}: is specified to be black

This results as one textobject - my question is how can I access each element of the textobject?

Crystal Reports itself can detect the difference because it does apply the different design time colouring.

I can't split out the objects from the textobject because {@ReferenceHeading} is a variable length and I want to maintain the look.

Any ideas?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Fergus,

First thing when attempting to make changes is to try it in CR Designer, then use the same work flow/method in code.

To see what the format looks like run your app in debug mode against the object you changed in the Designer and look at the properties. Then see if you can emulate that on the original object.

Keep it simple, no database connection and 2 text objects, one with the changes you want and one you can apply the change to in code.

If you get stuck attach the report to this post with the before and after objects only and I'll try it too.

Don

0 Kudos

Hi Don,

Thanks for the reply. I'm not sure if I explained myself properly:

In the attached report there is one text field made up of 2 formula fields:

@Heading - this is red
@Data - this is black

In code I want to set @Heading to be blue and leave @Data black.

When looping through the report objects, there is only 1 - so I can only change the colour for both.

Hope this makes sense?

Rename attached file to an rpt from a txt

Fergus

0 Kudos

Hi Fergus,

Thanks for the report, clarifies the question. So bottom line is no, you can't get to the individual object properties of a text object. However you can get to it if it is a text object and you set the color:

So the work around is you would have to rebuild the original text object with individual objects inserted into a new text object with the color set already on the individual object, being a field, text or any other type of object.

Once rebuild then use the .Add method, Clone the original and then Modify it or delete the original and rebuild the complete text object.

Drop the formula onto the report and then copy/Clone it a set the color property. then add it to a new text object and replace that with the old text object.

Don

0 Kudos

Thanks Don,

I'll give your workaround a go and let you know.

Fergus

Answers (0)