首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >将数组列表绑定到报表只产生一个结果

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

Stack Overflow用户
提问于 2016-09-14 21:00:04
回答 1查看 841关注 0票数 0

我正在尝试创建一个报告,它以为例,将来自sql查询的数据作为数据源。

一切运行顺利,所有3个测试记录都被放入数组列表中。然而,当报告显示时,只显示一个记录。

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

唱片班:

代码语言:javascript
运行
复制
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

创建报告:

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
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

输出:

EN

Stack Overflow用户

回答已采纳

发布于 2016-09-15 11:38:32

请参阅以下文档链接,以了解ArrayList的绑定如何与XtraReport一起工作:

如何:将报表绑定到数组列表

将报告绑定到列表

如何:将报表绑定到实现ITypedList接口的集合

向报告提供数据

从当前代码中,如果ArrayList包含多个项,则应显示多个记录。请阅读与数据源作业相关的XtraReport文档。

检查它正在按预期工作的示例,并使用您提供的代码片段。您可能以错误的方式在报表中使用了一些控件。请尝试删除并添加这些添加的附加控件,这些控件一个一个地绑定到数据源,这样您就可以找出导致问题的控件。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39499569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档