vb.netreportcomponentone

Problems adding DataTable as datasource in C1Report (VB) ComponentOne


I'm having troubles to assign a datasource to a code-generated c1report. This is the datatable data. This is the output result pdf view.

I'm using Visual Studio 2008 with ComponentOne 2009. The result pdf file as not the correct data, only the titles repeated to bottom. Then, this is the vb code:

    Public Function DataTableToC1Report(ByVal dtDatos As DataTable, ByVal strTitulo As String) As C1.C1Report.C1Report
    Dim c1r As New C1.C1Report.C1Report
    'Inicia control
    With c1r
        'limpia fields existentes
        .Clear()
        'configura fuente para todos los controles
        .Font.Name = "Tahoma"
        .Font.Size = 8
    End With
    'Inicializar diseño
    With c1r.Layout
        .Orientation = C1.C1Report.OrientationEnum.Portrait
        .Width = 6.5 * 1440 ' 8.5 - margen, en twips (aprox. son 567 twips por centímetro)
    End With
    'Crear encabezado y agregar field para titulo
    Dim f As C1.C1Report.Field
    With c1r.Sections(C1.C1Report.SectionTypeEnum.Header)
        .Height = 1440
        .Visible = True
        .BackColor = Color.FromArgb(200, 200, 200)
        f = .Fields.Add("FldTitle", strTitulo, 0, 0, 8000, 1440)
        f.Font.Size = 24
        f.Font.Bold = True
        f.ForeColor = Color.FromArgb(0, 0, 100)
    End With
    'Crea footer de página    
    With c1r.Sections(C1.C1Report.SectionTypeEnum.PageFooter)
        .Height = 500
        .Visible = True
        f = .Fields.Add("FldFtrLeft", """Generado el "" & Now", 0, 0, 4000, 300)
        f.Calculated = True
        f = .Fields.Add("FldFtrRight", """Página "" & Page & "" de "" & Pages", 4000, 0, 4000, 300)
        f.Calculated = True
        f.Align = C1.C1Report.FieldAlignEnum.RightTop
        f.Width = c1r.Layout.Width - f.Left
        f = .Fields.Add("FldLine", "", 0, 0, c1r.Layout.Width, 20)
        f.LineSlant = C1.C1Report.LineSlantEnum.NoSlant
        f.BorderStyle = C1.C1Report.BorderStyleEnum.Solid
        f.BorderColor = Color.FromArgb(0, 0, 100)
    End With
    'Genera títulos con fields
    With c1r.Sections(C1.C1Report.SectionTypeEnum.PageHeader)
        .Height = 500
        .Visible = True
        Dim i As Integer = 0
        Dim pIzq As Double = 0
        Dim pArriba As Double = 50
        Dim pAncho As Double = 800
        Dim pAltura As Double = 300
        For Each dc As DataColumn In dtDatos.Columns
            c1r.Font.Bold = True
            f = .Fields.Add("lblCol" & i.ToString, dc.ColumnName, pIzq, pArriba, pAncho, pAltura)
            c1r.Font.Bold = False
            f.Align = C1.C1Report.FieldAlignEnum.CenterMiddle
            i += 1
            pIzq += (pAncho + 100)
        Next
        f = .Fields.Add("FldLine", "", 0, 400, c1r.Layout.Width, 20)
        f.LineSlant = C1.C1Report.LineSlantEnum.NoSlant
        f.LineWidth = 50
        f.BorderColor = Color.FromArgb(100, 100, 100)
    End With
    'Crea sección de detalle   
    With c1r.Sections(C1.C1Report.SectionTypeEnum.Detail)
        Dim i As Integer = 0
        Dim pIzq As Double = 0
        Dim pArriba As Double = 0
        Dim pAncho As Double = 800
        Dim pAltura As Double = 300
        .Height = 330
        .Visible = True
        For Each dc As DataColumn In dtDatos.Columns
            c1r.Font.Bold = True
            f = .Fields.Add("fldCol" & i.ToString, dc.ColumnName, pIzq, pArriba, pAncho, pAltura)
            c1r.Font.Bold = False
            f.Calculated = False 'agregar que permita verificar si la columna debe ser calculada y poner en True
            f.CanGrow = False 'agregar que permita verificar si la columna puede crecer de tamaño
            f.Align = C1.C1Report.FieldAlignEnum.CenterMiddle
            'f.Width = c1r.Layout.Width - f.Left
            f.Font.Size = 6
            i += 1
            pIzq += (pAncho + 100)
        Next
        f = .Fields.Add("FldLine", "", 0, 310, c1r.Layout.Width, 20)
        f.LineSlant = C1.C1Report.LineSlantEnum.NoSlant
        f.BorderStyle = C1.C1Report.BorderStyleEnum.Solid
        f.BorderColor = Color.FromArgb(100, 100, 100)
    End With
    'Inicializar(DataSource)
    With c1r.DataSource
        '.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        '                    "Data Source=C:\...\ComponentOne Samples\Common\C1NWind.mdb;" & _
        '                    "Persist Security Info=False"
        '.RecordSource = "Employees"
        .Recordset = dtDatos
    End With
    Return c1r
End Function

Solution

  • I think the issue is because you've set the Calculated property of the fields added in the Detail section to False. You need to set it to True in order to bind data to the fields.