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

How to set DataSource to data that exists in an already instantiated object?

1 Answer 386 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Iron
Sean asked on 25 Oct 2017, 01:31 PM

Hello,

I have an object that collects data that then needs to be passed to the Report. A small example is below:

Imports Telerik.Reporting
 
Public Class Form1
    Public dataList As List(Of String)
 
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Fill data collection
        dataList.Add("Item 1")
        dataList.Add("Item 2")
        dataList.Add("Item 3")
 
        'Setup Telerik report
        Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor
        Dim deviceInfo As New System.Collections.Hashtable()
 
        Dim typeReportSource As New Telerik.Reporting.TypeReportSource
        typeReportSource.TypeName = GetType(Report1).AssemblyQualifiedName
 
        Dim result As Telerik.Reporting.Processing.RenderingResult = reportProcessor.RenderReport("PDF", typeReportSource, deviceInfo)
        Dim fileName As String = "testFile" & "." & result.Extension
        Dim path As String = "C:\Projects\Telerik"
        Dim filePath As String = System.IO.Path.Combine(path, fileName)
 
        'Save Telerik report
        Using fs As New System.IO.FileStream(filePath, System.IO.FileMode.Create)
            fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length)
        End Using
 
    End Sub
End Class
 
Public Class telerikAdapter
    Public Property New dataList As List(Of String)
 
    Public Sub New()
 
    End Sub
End Class

 

In this example, I need dataList to be available in the report. I can set the DataSource to the telerikAdapter class, or any of the other classes that exist in my application. However, these classes are instantiated when Telerik runs the report, and thus have no access to data that exists elsewhere in already instantiated objects.

 

I also tried passing parameters to the report, but I can't pass a collection. I need access to several rather deep collections of data in the report.

 

There must be a way to access dataList or to pass it in when the report is run, but I can't see it.

I'm working with Windows 7 32 bit, VB.NET, and WinForms, if it makes any difference.

 

 

 

1 Answer, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 25 Oct 2017, 02:51 PM
Hi Sean,

You can check an update in the support ticket which you opened for the same question. For other community members interested in this topic, below is the reply from the ticket:

"For such scenarios, we provide InstanceReportSource which can be used for passing report instance to ReportProcessor methods or when setting the report source of report viewers.

You can modify the report before passing it to RenderReport method and then wrap it into InstanceReportSource. Consider this example:
Dim report As Report1
' set the data source of report
report.DataSource = dataList
 
' or set data source of the inner data item (https://docs.telerik.com/reporting/data-items)
' Dim table As Telerik.Reporting.Table = TryCast(report.Items.Find("table1", True)(0), Telerik.Reporting.Table)
' table.DataSource = dataList
 
Dim reportProcessor As New Telerik.Reporting.Processing.ReportProcessor
Dim deviceInfo As New System.Collections.Hashtable()
 
Dim irs As New Telerik.Reporting.InstanceReportSource
irs.ReportDocument = report
 
Dim result As Telerik.Reporting.Processing.RenderingResult = reportProcessor.RenderReport("PDF", irs, deviceInfo)

"

I hope this will help.

Regards,
Katia
Progress 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
Sean
Top achievements
Rank 1
Iron
Answers by
Katia
Telerik team
Share this question
or