简体   繁体   English

在Telerik Reporting Visual Studio数据浏览器中显示子类的数据源

[英]Show data source(s) of child class in Telerik Reporting Visual Studio Data Explorer

In the Visual Studio Telerik Reporting Designer, the Data Explorer pane shows all data sources and their members for drag-and-drop to the designer. 在Visual Studio Telerik Reporting Designer中,“数据资源管理器”窗格显示所有数据源及其成员,以供拖放到设计器中。 We have reports that we are inheriting from a base report, however. 但是,我们有一些报告是从基本报告继承的。 In this case, the Data Explorer is showing the data source(s) of the base report ( objectDataSource.DataSource = typeof(BaseViewModel) ) rather than the child report ( objectDataSource.DataSource = typeof(ChildViewModel) ) that is currently open in the designer. 在这种情况下,数据资源管理器将显示基础报表( objectDataSource.DataSource = typeof(BaseViewModel) )的数据源,而不是当前在报表中objectDataSource.DataSource = typeof(ChildViewModel)的子报表( objectDataSource.DataSource = typeof(ChildViewModel) )。设计师。 Is there a way to get the Data Explorer to instead show the data sources of the child report? 有没有一种方法可以使数据资源管理器代替显示子报表的数据源?

Here is our relevant code: 这是我们的相关代码:

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();
    }
    ...
}

Hmm, seems to be a known issue with the Designer. 嗯,这似乎是设计师的已知问题。

When the report inherits from a custom class instead of Telerik.Reporting.Report you will lose the design-time support for this report in the Visual Studio report designer. 当报表从自定义类而不是Telerik.Reporting.Report继承时,您将在Visual Studio报表设计器中失去对此报表的设计时支持。 Thus, we recommend to inherit from the default Telerik.Reporting.Report class while designing and saving the report. 因此,我们建议在设计和保存报告时继承默认的Telerik.Reporting.Report类。 Once you are done you can change the inheritance to apply your custom class as a template. 完成后,您可以更改继承以将自定义类用作模板。

https://www.telerik.com/forums/report-inheritance#pckM3wbuxESVkRVB3icPWA https://www.telerik.com/forums/report-inheritance#pckM3wbuxESVkRVB3icPWA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM