将数组列表绑定到报表只会产生一个结果

Binding an Array List to a Report only yields one result

我正在尝试创建一个报告,该报告以 this 为例,从 sql 查询中获取数据作为数据源。

一切顺利,所有3条测试记录都放入数组列表中。但是,当报告显示只有一条记录时。

你能告诉我我做错了什么吗?谢谢

记录Class:

Public Class RecordGastoDotacion
Dim _id, _usuario As Integer
Dim _cantidad As String
Dim _fecha, _hora As String
Dim _desc As String

Public Sub New(ByVal id As Integer, ByVal fecha As Date, ByVal hora As Date, ByVal cantidad As String, ByVal descripcion As String, ByVal usuario As Integer)
    Me._id = id
    Me._fecha = fecha.ToString("dd/MM/yyyy")
    Me._hora = hora.ToString("hh:mm:ss")
    Me._cantidad = cantidad
    Me._desc = descripcion
    Me._usuario = usuario
End Sub

Public Property idgasto() As Integer
    Get
        Return _id
    End Get
    Set(ByVal Value As Integer)
        _id = Value
    End Set
End Property

Public Property fef() As String
    Get
        Return _fecha
    End Get
    Set(ByVal Value As String)
        _fecha = Value
    End Set
End Property

Public Property feh() As String
    Get
        Return _hora
    End Get
    Set(ByVal Value As String)
        _hora = Value
    End Set
End Property

Public Property cant() As String
    Get
        Return _cantidad
    End Get
    Set(ByVal Value As String)
        _cantidad = Value
    End Set
End Property

Public Property descr() As String
    Get
        Return _desc
    End Get
    Set(ByVal Value As String)
        _desc = Value
    End Set
End Property

Public Property usuario() As Integer
    Get
        Return _usuario
    End Get
    Set(ByVal Value As Integer)
        _usuario = Value
    End Set
End Property
End Class

报告创建:

Cmd.CommandText = String.Format("SELECT gas.idre_gasto as idgasto, date(fe.fecha) as fef, time(fe.fecha) as feh, gas.cantidad as cant, gas.descripcion as descr, gas.re_usuario_idre_usuario as usuario FROM re_gasto as gas INNER JOIN re_corte_caja AS cor ON gas.re_corte_caja_idre_corte_caja = cor.idre_corte_caja
inner join re_fecha as fe on cor.re_fecha_idre_fecha = fe.idre_fecha WHERE date(fe.fecha) BETWEEN '{0:yyyy-MM-dd}' AND '{1:yyyy-MM-dd}' AND cor.estatus = {2}",
                                        DateTimePicker1.Value, DateTimePicker2.Value, ESTATUS_ACTIVO)
        rs = Cmd.Execute

        Dim listDataSource As New ArrayList()

        Do While Not rs.EOF
            listDataSource.Add(New RecordGastoDotacion(CInt(rs("idgasto").Value), CType(rs("fef").Value, Date), CType(rs("feh").Value, Date),
                                                       CType(rs("cant").Value, String), CType(rs("descr").Value, String),
                                                       CInt(rs("usuario").Value)))
            rs.MoveNext()
        Loop

        Dim gastos As New ReporteGastos() With {.Margins = New Printing.Margins(100, 100, 25, 25), .DataSource = listDataSource}

        gastos.XrLabel4.Text = String.Format("Día Creación: {0}", Now.ToString("dd/MM/yyyy"))
        gastos.XrLabel5.Text = String.Format("Hora Creación: {0}", Now.ToString("hh:MM"))


        gastos.AddBoundLabel("idgasto", New Rectangle(100, 20, 50, 30))
        gastos.AddBoundLabel("fef", New Rectangle(150, 20, 100, 30))
        gastos.AddBoundLabel("feh", New Rectangle(250, 20, 100, 30))
        gastos.AddBoundLabel("cant", New Rectangle(350, 20, 50, 30))
        gastos.AddBoundLabel("descr", New Rectangle(450, 20, 100, 30))
        gastos.AddBoundLabel("usuario", New Rectangle(550, 20, 50, 30))

        gastos.XrLabel12.Text = total

        Using printTool As New ReportPrintTool(gastos)
            printTool.ShowRibbonPreviewDialog(UserLookAndFeel.Default)
        End Using

ReporteGastos:

Imports System.Drawing
Imports DevExpress.XtraReports.UI

Public Class ReporteGastos
Public Sub AddBoundLabel(ByVal bindingMember As String, ByVal bounds As Rectangle)
    ' Create a label. 
    Dim label As New XRLabel()

    ' Add the label to the report's Detail band. 
    Detail.Controls.Add(label)

    ' Set its location and size. 
    label.Location = bounds.Location
    label.Size = bounds.Size

    ' Bind it to the bindingMember data field. 
    ' When the dataSource parameter is Nothing, the report's data source is used. 
    label.DataBindings.Add("Text", Nothing, bindingMember)
End Sub
End Class

输出:

参考以下文档链接了解 ArrayList 的绑定如何与 XtraReport 一起工作:
How to: Bind a Report to an Array List
Binding a Report to Lists
How to: Bind a Report to a Collection that Implements the ITypedList Interface
Providing Data to Reports

根据您当前的代码,如果 ArrayList 包含多个项目,它应该显示多个记录。请阅读与数据源分配相关的 XtraReport 文档..

检查 example 它是否按预期使用您提供的代码片段工作。您可能以错误的方式在报告中进行了一些控制。请尝试将这些与数据源绑定的额外控件一一删除并添加,以便您找出导致问题的控件。