在visual studio telerik报表设计器中,数据资源管理器窗格显示所有数据源及其成员,以便拖放到设计器中。但是,我们有从基报表继承的报表。在这种情况下,数据资源管理器将显示基本报表的数据源(
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();
}
...
}