Solved

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

Posted on 2010-11-16
6
603 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

726 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