在Visual Studio Telerik Reporting Designer中,“数据资源管理器”窗格显示所有数据源及其成员,以便拖放到设计器中。但是,我们有报告说我们继承了基础报告。在这种情况下,数据资源管理器显示基本报告(objectDataSource.DataSource = typeof(BaseViewModel)
)的数据源,而不是设计器中当前打开的子报告(objectDataSource.DataSource = typeof(ChildViewModel)
)。有没有办法让数据资源管理器显示子报告的数据源?
这是我们的相关代码:
public partial class BaseReport
{
private void InitializeComponent()
{
objectDataSource = new Telerik.Reporting.ObjectDataSource();
objectDataSource.DataMember = "GetRecords";
objectDataSource.DataSource = typeof(BaseViewModel);
objectDataSource.Name = "objectDataSource";
DataSource = this.objectDataSource;
}
protected Telerik.Reporting.ObjectDataSource objectDataSource;
}
public class BaseViewModel
{
...
// without this dummy method, an exception is thrown in Data Explorer
public IEnumerable<string> GetRecords()
{
return new List<string>();
}
...
}
public partial class ChildReport : BaseReport
{
public ChildReport()
{
InitializeComponent();
objectDataSource.DataSource = typeof(ChildViewModel);
}
}
public class ChildViewModel
{
...
public IEnumerable<MyRecord> GetRecords()
{
return GetMyRecords();
}
...
}
嗯,似乎是设计师的一个已知问题。
当报表继承自定义类而不是Telerik.Reporting.Report时,您将在Visual Studio报表设计器中失去对此报表的设计时支持。因此,我们建议在设计和保存报表时继承默认的Telerik.Reporting.Report类。完成后,您可以更改继承以将自定义类应用为模板。
https://www.telerik.com/forums/report-inheritance#pckM3wbuxESVkRVB3icPWA