代码之家  ›  专栏  ›  技术社区  ›  ScottStonehouse

使用BindingSource对报表查看器中的报表数据进行排序

  •  0
  • ScottStonehouse  · 技术社区  · 17 年前

    我正在尝试让ReportViewer显示来自BindingSource(vb.net WinForms)的数据。

    我在基础数据集上构建了报表。然后我将数据源实例配置为bindingsource。我认为这将应用排序、筛选等,但看起来数据来自数据集而不是bindingsource。

    我怀疑我遗漏了一些简单的东西。

    更新:或者可能不是那么简单-我几天前发布了这个,但仍然没有人知道答案!也许我想做一些不能做的事?

    2 回复  |  直到 17 年前
        1
  •  0
  •   Anthony    17 年前

    您需要在报告中(在RDL中)指定排序,因为它应用自己的排序逻辑。

        2
  •  0
  •   ScottStonehouse    17 年前

    这是我使用的解决方案。将BindingSource中的数据放入数据表,然后让报表使用该数据表。

        ReportViewer1.Reset()
        Dim dt As DataTable
        dt = DirectCast(Form1.ProgActnBindingSource.Current, DataRowView).DataView.ToTable
    
        Dim rs = New ReportDataSource
        rs.Name = "name"
        rs.Value = dt
    
        ReportViewer1.ProcessingMode = ProcessingMode.Local
        ReportViewer1.LocalReport.DataSources.Clear()
        ReportViewer1.LocalReport.DataSources.Add(rs)
        ReportViewer1.LocalReport.ReportEmbeddedResource = "projectname.Report1.rdlc"
    
        Me.ReportViewer1.RefreshReport()