Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

VS 2010 Assigning an Object to ReportViewer control at Run Time.

$
0
0
Hi,

I'm working with VB.NET Visual studio 2012 Ultimate.

I designed a report via the ReportViewer. When I Initially setup the report, I entered as the Data Source, a Class Name from an Object that I developed in a DLL. I was able to select the Property Names of the data from my Object in designing the Form.

However, at run time, I want to change the data source to the instantiated object from my DLL.

Example: This is the Class in my DLL (only used as an example - not my actual code)

Code:

Public Class MyClass
    Private s_MyName as string
    Public ReadOnly Property MyName()
        Get
            s_MyName = "George Washington"
            MyName = s_MyName
        End Get
    End Property 
End Class

I built the class into a DLL called MyClass. From my VB.NET Windows Forms App, I can instantiate the object and successfully access the properties.

This code in my client module returns "George Washington"

dim objA = New MyClass
msgbox objA.MyName

Next, I setup the ReportView with a logo and I entered "MyClass" as the Datasource to my report. On the report I dragged the MyName property to the report designer.

However, when I run my module, "MyClass" is not instantiated and does not appear on the report. I tried this to reset the datasource at run time:

Code:


dim objA = New MyClass
msgbox objA.MyName

Dim ds As Microsoft.Reporting.WinForms.ReportDataSource = New Microsoft.Reporting.WinForms.ReportDataSource

        ds.Name = "objA"
        ds.Value = objA


        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Me.ReportViewer1.LocalReport.DataSources.Add(ds)

        Me.ReportViewer1.RefreshReport()

But apparently I can't set the datasource to an object that is not a table????? Is it possible to set the datasource of my report to an object that I instantiate in my program at run time?

Thanks for any help ....

Viewing all articles
Browse latest Browse all 42220

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>