Winforms Report(RDLC)在运行时与具有列表属性的对象绑定

本文关键字:列表 属性 绑定 对象 Report RDLC 运行时 Winforms | 更新日期: 2023-09-27 18:21:19

我有一个对象,它具有关于订单的头级详细信息,以及订单详细信息列表。

标题信息填充得很好,但我不知道如何将订单详细信息列表绑定到报告上的tablix。

这是错误的做法吗?数据连接是在运行时确定的,所以我不认为我可以简单地将子报表挂接到数据库并传递过滤器。

编辑:我应该添加一个带有ReportViewer的父窗体,如果它有区别的话。这就是我设置数据源的地方。

    public class FormulaHeaderModel
{
    public string flavor { get; set; }
    public string name { get; set; }
    public string author { get; set; }
    public string formulaId { get; set; }
    public string formulaNumber { get; set; }
    public string formulaType { get; set; }
    public string accessLevel { get; set; }
    public string createdOnDate { get; set; }
    public string formulaWeight { get; set; }
    public string note { get; set; }
    public List<FormulaDetailModel> dataCharacterizing { get; set; }
    public List<FormulaDetailModel> dataContributory { get; set; }
    public List<FormulaDetailModel> dataGlobal { get; set; }
    public List<FormulaDetailModel> dataCarrier { get; set; }
}
    public class FormulaDetailModel
{
    public int formulaID { get; set; }
    public int ingredientTypeId { get; set; }
    public string codeFema { get; set; }
    public decimal ingredientCost { get; set; }
    public string name { get; set; }
    public string natural { get; set; }
    public decimal ppm { get; set; }
    public decimal percentSolution { get; set; }
    public decimal grams {get; set;}
}

每个单子我都需要一张表格。

因此,顶部是字符串级别的信息,然后是4个FormulaDetailModel列表中每一个的标签和tablix(或任何真正的)。

Winforms Report(RDLC)在运行时与具有列表属性的对象绑定

明白了。我可以添加第二个数据源,只要名称与表设置的数据集名称匹配。

this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FormulaDetailModel", fhModel.dataCharacterizing ));