Skip to Content
0
Former Member
Jun 09, 2009 at 02:53 AM

Date Formatting in a Result Field: Crystal Reports 2008

153 Views

I'm modifying a report at runtime in c# .Net using Crystal Reports 2008.

I'm having trouble modifying a date fields format. I have accessed the DateFieldFormat object, and modified the properties, but only the SystemDefaultType property seems to have any affect.

If the Date format is set in the Visual Report Designer I can see the details of the format in DateFieldObject, but editing these values doesn't have any affect on the report once displayed.

Here is a sample of the code i'm using:

public Form1()
{
	InitializeComponent();
	CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
	ISCDReportClientDocument reportClientDocument;

	// Load Report
	reportDocument.Load(@"C:\myReport.rpt");
	reportClientDocument = reportDocument.ReportClientDocument;

	// Access Field
	FieldObject fieldObject = (FieldObject)reportClientDocument.ReportDefinition.DetailArea.Sections[0].ReportObjects["DateField1"];

	// These work, if I want to use one of the default formats
	// fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeUseLongDate;
	// fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeUseShortDate;

	// I don't want to use one of the defaults.
	fieldObject.FieldFormat.DateFormat.SystemDefaultType = CrDateSystemDefaultTypeEnum.crDateSystemDefaultTypeNotUsingDefaults;

	// I want to change the order of the values
	fieldObject.FieldFormat.DateFormat.DateOrder = CrDateOrderEnum.crDateOrderDayMonthYear;

	// Display the report in the viewer
	crystalViewer.ReportSource = rpt.rcd.ReportSource;

}

I'm assuming I'm missing something about the object model here, but I can't find any good reference to it. Can someone help me out?

Thanks!