Solved

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

Posted on 2010-11-16
6
602 Views
Last Modified: 2013-11-26
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
Comment
Question by:shlafrock
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:RADONE242
ID: 34149645
What type of object? Can it be added as a data source? Perhaps you can just pass values from your object as parameters?
0
 
LVL 1

Author Comment

by:shlafrock
ID: 34149678
ok, so how do I pass values as parameters?
0
 
LVL 1

Author Comment

by:shlafrock
ID: 34149783
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Expert Comment

by:RADONE242
ID: 34149808
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
 
LVL 1

Accepted Solution

by:
RADONE242 earned 500 total points
ID: 34149830
=Parameters!TestPass.Value
0
 
LVL 1

Author Closing Comment

by:shlafrock
ID: 34149935
perfect. thanks.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question