This is a migrated thread and some comments may be shown as answers.

Sub Report Won't Display

4 Answers 589 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Haim
Top achievements
Rank 1
Haim asked on 20 Jun 2016, 10:37 AM

I am trying to create a simple Master Details report in a Winform application with a Master Table, Detail Table in a dataset.  I have followed the instructions for setting up a Master Details report.  My SubReport (CheckItemsSRPT) has a Parameter called "IDNum"  defined as an integer (as is the field idnum) which allows nulls.  , and a filter =fields.IDNum = =Parameters.IDNum.Value.

The Master Reports is grouped by the IDNum field.  It has a subreport in the details section whose ReportSource  is defined to the type CheckItemsSRPT with Parameter.IDNum, and a filter {=Fields.IDNum = =Parameter.IDNum.Value}

When I Preview the report in design time the data in the details section shows up as expected.

During runtime a dataset is filled with data and transferred  to the report. (See Code Below) 

The data in the Master table appears in the report as expected, but the subreport only renders the data of the default value of the Parameter.IDNum  (Also the report only renders after a manual refresh). 

I have set a breakpoint both at the SubReport1.Itemdatabinding event in the ChecksReport, and in the itemdatabinding event of the CheckItemsSRPT and the parameter.IDNum does not change its value.  What am I missing?

 

'Master report datasource      
    ObjectDataSource()
        mydsItems.DataSource = BudgetsDS1
        mydsItems.DataMember = "CheckItems"
'Master Report
        Dim myrpt As new CheckRpt()
        myrpt.DataSource = myds
'Detail Report
        dim mysubrpt as new CheckItemsSRPT()
        mysubrpt.DataSource = mydsItems
        Dim rssub as new InstanceReportSource
        rssub.ReportDocument = mysubrpt
'Assign Details to SubReport Control
        Dim myctrl As SubReport =TryCast( myrpt.Items.Find("SubReport1",True)(0),SubReport)
        myctrl.ReportSource= rssub
'Assign ReportSource to Viewer Control in form      
        Dim ms as new InstanceReportSource
        ms.ReportDocument = myrpt
        Dim myfrm as new CheckViewervb()
        myfrm.ReportViewer1.ReportSource = ms
        myfrm.Show()

 

4 Answers, 1 is accepted

Sort by
0
Haim
Top achievements
Rank 1
answered on 20 Jun 2016, 11:49 AM

I finally got it to work with the help of this post.  (I guess it helps to post a question to find an answer on your own). The corrected code is pasted below.  Basically I did not create a new ReportInstance for the subreport and just assigned the data source directly to the report object of the subreport control. 

The order of assigning the dataSource is important.  If I assigned the Main Form's data source before assigning the SubReport's datsource, then the Main Report's Group's headers and footers did not render data (but the subreport rendered correctly.

       Dim myds as New ObjectDataSource()
        myds.DataSource = BudgetsDS1
        myds.DataMember = "Checks"
         
        Dim mydsItems = New ObjectDataSource()
        mydsItems.DataSource = BudgetsDS1
        mydsItems.DataMember = "CheckItems"
        
        Dim myrpt As new CheckRpt()
        Dim myctrl As SubReport =TryCast( myrpt.Items.Find("SubReport1",True)(0),SubReport)
'** Important the subreports datasource must be set before the main Report
        myctrl.Report.DataSource = mydsItems
        myrpt.DataSource = myds
        'dim mysubrpt as new CheckItemsSRPT()
'** This was eliminated from the original post's code
        'mysubrpt.DataSource = mydsItems
        'Dim rssub as new InstanceReportSource
        'rssub.ReportDocument = mysubrpt
         
        Dim ms as new InstanceReportSource
        ms.ReportDocument = myrpt
        Dim myfrm as new CheckViewervb()
        myfrm.ReportViewer1.ReportSource = ms
'this still doesn't do anything.  I need to refresh the report manually
        myfrm.ReportViewer1.Refresh()
        myfrm.Show()

0
Nasko
Telerik team
answered on 22 Jun 2016, 03:02 PM
Hello Haim,

Note that when assigning a new report source to the SubReport item, you are also removing any report parameters defined in the ReportSource.Parameters collection:
Dim rssub As New InstanceReportSource
rssub.ReportDocument = mysubrpt
'Assign Details to SubReport Control
Dim myctrl As SubReport = TryCast( myrpt.Items.Find("SubReport1",True)(0),SubReport)
myctrl.ReportSource = rssub

You need to fill the .Parameters collection (or the myctrl.ReportSource.Parameters collection) for the initial solution to be correct.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Haim
Top achievements
Rank 1
answered on 23 Jun 2016, 10:43 AM

Thank you Nasko.  Your explanation was good.   I still have problems in that I have to manually refresh the report on the form with the report viewer.  How can I get it to open with the data displayed?  i tried

myfrm.ReportViewer1.Refresh()  (myfrm contains the report viewer)
        myfrm.Show()

and also in reverse order but it doesn't make a difference.

 

Haim

0
Nasko
Telerik team
answered on 24 Jun 2016, 06:30 AM
Hello Haim,

Try using the ReportViewer.RefreshReport Method to refresh the report. More examples are available here.

Regards,
Nasko
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Haim
Top achievements
Rank 1
Answers by
Haim
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or