• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 611
  • Last Modified:

How to pass an object to ReportViewer WinForm control in VS 2008 ?

I have a WinForm with ReportViewer control and I need to pass some data
to the report I created. It's just few variables, not data from db.

How can I pass my custom object to my report ?

I think I'm looking for something like :

this.reportViewer1.RefreshReport(myObject);
or
this.reportViewer1.PassObject(myObject);
or whatever,
so I can somehow use this object in rdlc file .

0
shlafrock
Asked:
shlafrock
  • 3
  • 3
1 Solution
 
RADONE242Commented:
What type of object? Can it be added as a data source? Perhaps you can just pass values from your object as parameters?
0
 
shlafrockAuthor Commented:
ok, so how do I pass values as parameters?
0
 
shlafrockAuthor Commented:
i think i got it :
            List<ReportParameter> paramList=new List<ReportParameter>();
            paramList.Add(new ReportParameter("TestPass", "10"));
            this.reportViewer1.ServerReport.SetParameters(paramList);
            this.reportViewer1.RefreshReport();  

but now how do I access these parameters in rdlc file ?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
RADONE242Commented:
First add your parameters to the report. Click Reports from the file menu, then report parameters.
Next from your form with the report, dim an array for the parameters you wish to pass

        Dim parItems(2) As ReportParameter
        parItems(0) = New ReportParameter("Parameter1", MyObject.FirstName)
        parItems(1) = New ReportParameter("Parameter2", MyObject.LastName)
        parItems(2) = New ReportParameter("Parameter3", MyObject.Address)

Then before refreshing the report add your parameters

Me.ctlReportViewer.LocalReport.SetParameters(parItems)

0
 
RADONE242Commented:
=Parameters!TestPass.Value
0
 
shlafrockAuthor Commented:
perfect. thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now