SAP Knowledge Base Article - Public

2003581 - How to set the Localization for a Crystal Reports .NET application

Symptom

Users would like to set the local language settings for use in a .NET application from the default locale.

Environment

  • Crystal Reports developer for Visual Studio
  • Visual Studio 2010/2012/2013

Resolution

Create a Windows List box and label it lstCELocale.

Using this code in the form load you can get/set the locale:

Note: the Locale must be set before loading the report.

public frmMain()
{
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent();

    Array valArray = Enum.GetValues(typeof(CrystalDecisions.ReportAppServer.CommonControls.CeLocale));
    foreach (object obj in valArray)
    {
        lstCeLocale.Items.Add(obj);
    }

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
}

You will see the ceLocalization ENUM's listed and can set the selected with this code:

CrystalDecisions.ReportAppServer.CommonControls.CeLocale myceLocale;

private void lstCeLocale_SelectedIndexChanged(object sender, EventArgs e)
{
    //this is the routine to set the default language locale for the report. Must be done before the report is loaded.
    CrystalDecisions.ReportAppServer.CommonControls.CeLocale myceLocale = (CrystalDecisions.ReportAppServer.CommonControls.CeLocale)lstCeLocale.SelectedItem;

    try
    {
        rpt.ReportClientDocument.LocaleID = (CrystalDecisions.ReportAppServer.DataDefModel.CeLocale)myceLocale;
    }
    catch (Exception ex)
    {
        MessageBox.Show("ERROR: " + ex.Message);
    }
}

To change the CR Windows Form Viewer to match the locale selected use this line:

crystalReportViewer1.SetProductLocale(LCID);

To see what the LCID values are refer to Microsoft's article for the values:

http://msdn.microsoft.com/en-us/library/cc233968.aspx

Or to automatically set the viewer to the same as the report you can use this:

int x = (int)rpt.ReportClientDocument.LocaleID;
crystalReportViewer1.SetProductLocale(x);

NOTE: if you do not have the language installed the viewer will default to English ( or you local codepage - default language)

 

Keywords

celocale, cr for vs, crforvs, Crystal Reports Developer for Visual Studio, localization , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio ; SAP Crystal Reports, version for Visual Studio .NET 2008