Pergunta

I have a report that has 3 datasets.

DS1 – Region Number, District Name/Number, Test Name, Test Count, Test Charge for last month

DS2 – Region Number District Number, Test Number, MMYYYY, Test Count, Test Charge for last year, grouped by MMYYYY

DS3 – Region Number Test Number, MMYYYY, Test Count, Test Charge for last year, grouped by MMYYYY

Report Layout

Region Name (GroupHeader)
   District Name(GroupHeader) 
      Test Name (Details Section)   
   District Chart, bar chart of the last 12 months activity for a district/test combo (DS2) (GroupFooter)
Region Charts (GroupFooter –(the number of charts can be 1 to 20 based on the district data))

Each dataset contains all the respective data & I perform a RowFilter to get the subset of data needed for the District Chart.

The issue I am having is when the Region charts are generated (the number of charts can be 1 to 20 because it is summarizing the districts totals), the charts display the correct number of times, but all the charts displays the data from the last RowFilter.

Other than the Main report, I have tried combinations of the Format & ReportStart Events. I have stepped through the code & the RowFilter is executed for each PanelNumber.

The Code is below....

Main Report

Private Sub grpRegionFooter_Format(sender As System.Object, e As System.EventArgs) Handles grpRegionFooter.Format
    Dim rpt As New rptDetailExpRegion_Graph
    Dim iWhere As String = txtRegion.Value.ToString.Trim
    Dim WhereClause As String = "Region = " + iWhere.Trim
    SubReport2.Report = rpt
    rpt.DataTable = dsGraphData.Tables(2)
    rpt.Where = WhereClause
    rpt.Text = txtRegion.Text
End Sub

SubReport 1 (rptDetailExpRegion_Graph)

Private Sub rptDetailExpRegion_Graph_ReportStart(sender As Object, e As System.EventArgs) Handles Me.ReportStart
    Dim Panels As DataTable
    Dim DR As DataRow
    Dim WhereClause As String = Where
    Panels = DS.DefaultView.ToTable(True, "PanelNumber")
    Panels.DefaultView.Sort = "PanelNumber"


    For Each DR In Panels.Rows
        Dim rpt As New rptDetailExpRegion_Graph2
        WhereClause = Where + " AND PanelNumber = " + DR.Item(0).ToString
        srRegionGraphs.Report = rpt
        rpt.Where = WhereClause

        DS.DefaultView.RowFilter = WhereClause
        rpt.DataSource = DS.DefaultView

        rpt.DataSource = DS.DefaultView
        rpt.DataTable = DS

    Next
End Sub

SubReport 2 – Has the graph (rptDetailExpRegion_Graph2)

Private Sub GroupHeader1_Format_1(sender As System.Object, e As System.EventArgs) Handles GroupHeader1.Format
    Dim WhereClause As String
    WhereClause = "Region = " + txtRegion.Text + " and PanelNumber = " + txtPanelNumber.Text
    ds1 = New DataView(DS, WhereClause, "Region", DataViewRowState.CurrentRows)
    srRegionGraphs.DataSource = ds1
End Sub
Foi útil?

Solução

In the code you posted for *SubReport 1 (rptDetailExpRegion_Graph)* you are looping through the DataTable rows and repeatedly setting the subreport's DataSource/DataTable fields. Since the report start event is raised only once before the report begins processing only the last time the DataSource will be used.

If I understand correctly what you're trying to do, a better way to do this is to set the parent report's datasource to the entire Panel's DataSet. This way, the Detail section for the parent report will repeat for each Panel. In the Detail section you can place a subreport with the charts or you can place the charts in that detail section directly and rebind each individual chart based on the current panel.

Check out the Subreports with Run-Time Data Sources walkthrough. Pay special attention to how the Where clause of the subreport is modified in the Format event of the Detail section (expand the To add code to assign a data source for the Child Report (rptSub) heading). The filtering of the Subreport data is done in the Detail section's format event because that event is raised for each record in the parent report. If that filtering was done in in the ReportStart event it wouldn't work since it would apply only one filter.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top