I try to translate all reports fields before show it to report designer(from report viewer to report designer). using this class
#region #Usings
using System;
using System.Windows.Forms;
using DevExpress.Data;
using DevExpress.DataAccess.ObjectBinding;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.UI;
using MrSales.MrSLanguages;
using MrSales.MrSModels.dataObjects;
#endregion #Usings
namespace MrSales.MrSModels.TablesTranslations.TablesTranslations.GeneralReportTranslation
{
#region #SqlDataSource
public class GeneralReportTranslation : ObjectDataSource, IDisplayNameProvider
{
public GeneralReportTranslation()
{
}
XtraReport report = null;
public GeneralReportTranslation(ObjectDataSource copyFrom, XtraReport _report)
{
this.LoadFromXml(copyFrom.SaveToXml());
report = _report;
}
string IDisplayNameProvider.GetDataSourceDisplayName()
{
return report.DisplayName;
}
string IDisplayNameProvider.GetFieldDisplayName(string[] fieldAccessors)
{
string fieldName = fieldAccessors[fieldAccessors.Length - 1];
return ChangeNames(fieldName);
}
public string ChangeNames(string name)
{
string result = string.Empty;
if (name == "people_data")
{
result = strings.PEOPLE_DATA;
}
else if (name == "Unit")
{
result = strings.UNIT;
}
else if (name == "Tax")
{
result = strings.TAX_NUM;
}
else
{
try
{
result = strings.ResourceManager.GetString(name, strings.Culture);
}
catch
{
return null;
}
}
return result;
}
}
#endregion #SqlDataSource
}
in the report designer:
private void loadReportDesign( XtraReport report )
{
report.DataSource = new GeneralReportTranslation((ObjectDataSource)report.DataSource, report);
reportDesigner1.OpenReport(report);
}
in the report viewer:
XtraReport report = documentViewer1.DocumentSource as XtraReport;
MrSViews.CompanyConfig.ReportDesigner frm = new MrSViews.CompanyConfig.ReportDesigner(report);
frm.TopMost = false;
frm.Show();
but this error
System.InvalidCastException: 'Unable to cast object of type 'System.Collections.Generic.List`1[MrSales.MrSModels.dataObjects.CLSPeopleHistory]' to type 'DevExpress.DataAccess.ObjectBinding.ObjectDataSource'.'
appear at
<pre>report.DataSource = new GeneralReportTranslation((ObjectDataSource)report.DataSource, report);
What I have tried:
i tried to ignoring the report viewer and load the report in the report designer with this code and it work:
CustomerMove report_CustomerMove = new CustomerMove();
report_CustomerMove.DataSource = new GeneralReportTranslation((ObjectDataSource)report_CustomerMove.DataSource, report);
reportDesigner1.OpenReport(report_CustomerMove);
it work but i can't repair my code to work fine when i pass the report from report viewer to the report designer.