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

Build a report programmatically

7 Answers 902 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Anoop
Top achievements
Rank 1
Anoop asked on 09 May 2011, 06:32 AM

Hi,

I am trying to build a report programmatically without using the wizard. In this report am using parameter which also should be done programmatically according to my data, and through a query that also be added.

 

I tried this >> http://www.telerik.com/help/reporting/programmatic-creating-report.html

 

But I don’t know why am getting and empty report?!

 

Also the parameters and filter?!

 

Is there is any procedures behind that


this is a part of what i did, i might be missing something,, lemme know please?
Thanks in advance

Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports Telerik.Reporting
Imports Telerik.Reporting.Drawing
Imports System.Data.SqlClient
  
Partial Public Class Visitreport
    Inherits Telerik.Reporting.Report
    Public Sub New()
        InitializeComponent()
        Dim report As New Report()
        'Dim sql As String = "SELECT  "
        Dim sql As String = ""
        Dim connectionString As String = ""
        Dim adapter As New SqlDataAdapter(sql, connectionString)
        report.DataSource = adapter
        'creating item programatically 
        Dim detail As New DetailSection()
        Me.detail.Height = New Telerik.Reporting.Drawing.Unit(3, Telerik.Reporting.Drawing.UnitType.Inch)
        Me.detail.Name = "detail"
        report.Items.Add(DirectCast(detail, ReportItemBase))
  
        Dim panel1 As New Telerik.Reporting.Panel()
        Dim textBox1 As New Telerik.Reporting.TextBox()
  
        'panel1
  
  
        panel1.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(1, Telerik.Reporting.Drawing.UnitType.Cm))
        panel1.Size = New Telerik.Reporting.Drawing.SizeU(New Telerik.Reporting.Drawing.Unit(8.5, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(3.5, Telerik.Reporting.Drawing.UnitType.Cm))
        panel1.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid
  
        'textBox1
  
  
        textBox1.Location = New Telerik.Reporting.Drawing.PointU(New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(0, Telerik.Reporting.Drawing.UnitType.Cm))
        textBox1.Name = "NameDataTextBox"
        textBox1.Size = New Telerik.Reporting.Drawing.SizeU(New Telerik.Reporting.Drawing.Unit(5, Telerik.Reporting.Drawing.UnitType.Cm), New Telerik.Reporting.Drawing.Unit(0.6, Telerik.Reporting.Drawing.UnitType.Cm))
        textBox1.Style.BorderStyle.Default = Telerik.Reporting.Drawing.BorderType.Solid
        textBox1.StyleName = "Data"
        textBox1.Value = "=Fields.AssignTo"
  
        panel1.Items.AddRange(New Telerik.Reporting.ReportItemBase() {textBox1})
        detail.Items.AddRange(New Telerik.Reporting.ReportItemBase() {panel1})
  
        Dim reportParameter1 As New Telerik.Reporting.ReportParameter()
        reportParameter1.Name = "Parameter1"
        reportParameter1.Text = "Enter Value for Parameter1"
        reportParameter1.Type = Telerik.Reporting.ReportParameterType.Integer
        reportParameter1.AllowBlank = False
        reportParameter1.AllowNull = False
        reportParameter1.Value = "=10"
        reportParameter1.Visible = True
        report.ReportParameters.Add(reportParameter1)
        reportParameter1.AvailableValues.DataSource = adapter
        reportParameter1.AvailableValues.ValueMember = "= Fields.AssignTo"
        reportParameter1.AvailableValues.DisplayMember = "= Fields.AssignTo"
        Dim filter1 As New Telerik.Reporting.Data.Filter()
        filter1.Expression = "=Fields.AssignTo"
        filter1.Operator = Telerik.Reporting.Data.FilterOperator.Equal
        filter1.Value = "=Parameters.AssignTo"
        reportParameter1.AvailableValues.Filters.AddRange(New Telerik.Reporting.Data.Filter() {filter1})
        Dim sorting1 As New Telerik.Reporting.Data.Sorting()
        sorting1.Expression = "=Fields.AssignTo"
        sorting1.Direction = Telerik.Reporting.Data.SortDirection.Asc
        reportParameter1.AvailableValues.Sortings.AddRange(New Telerik.Reporting.Data.Sorting() {sorting1})
  
  
        '   report.ReportParameters("AssignTo").Value = ""
  
    End Sub
  
    Private Sub detail_ItemDataBound(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles detail.ItemDataBound
        'Take the Telerik.Reporting.Processing.Report instance
        'Dim report As Telerik.Reporting.Processing.Report = DirectCast(sender, Telerik.Reporting.Processing.Report)
  
        ' Transfer the value of the processing instance of ReportParameter
        ' to the parameter value of the sqlDataSource component
        '   Me.SqlDataSource1.Parameters(0).Value = report.Parameters("AssignTo").Value
  
        ' Set the SqlDataSource component as it's DataSource
        report.DataSource = Me.SqlDataSource1
  
    End Sub
End Class

7 Answers, 1 is accepted

Sort by
0
Anoop
Top achievements
Rank 1
answered on 10 May 2011, 06:20 AM
the above code should be in the report or in the loadform??
0
veena
Top achievements
Rank 1
answered on 10 May 2011, 06:19 PM
Hi Anoop,

I have added a post to create report dynamically based on datasource. The only problem I face is Reportheader where I place column heading, is not on all pages. I wish instead of dynamically creating columns I could load them into table. Have a look, if you can do it please add your solution to the post

http://www.telerik.com/community/forums/reporting/telerik-reporting/fully-dynamic-report.aspx
0
Hrisi
Telerik team
answered on 12 May 2011, 12:55 PM
Hello Anoop,

If you want to build the report programmatically, you should be familiar with the Report definition object model. The best guide for this is the code generated in [YourReport].Designer.vb by using the Report Designer in Visual Studio.

From your code in the constructor you should remove this line:
    Dim report As New Report()
and instead of using the local report variable, consider using the Me.

Best wishes,
Hrisi
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Anoop
Top achievements
Rank 1
answered on 25 May 2011, 10:30 AM

I had added a parameter, however am not able to build the datasourse object

 

I do not want to use the sqldatasourse control, so how can I build it to get the data from the parameter I create.

How to bind the data to it

 

I use this code to build the parameter



Dim reportParameter1 As New Telerik.Reporting.ReportParameter()
        reportParameter1.Name = "Parameter1"
        reportParameter1.Text = "Category"
        reportParameter1.Type = Telerik.Reporting.ReportParameterType.String
        reportParameter1.AllowBlank = False
        reportParameter1.AllowNull = False
        reportParameter1.Value = "= Fields.Category"
        reportParameter1.Visible = True
        Report.ReportParameters.Add(reportParameter1)
  
reportParameter1.AvailableValues.DataSource = objectDataSource1
        reportParameter1.AvailableValues.ValueMember = "= Fields.Category"
        reportParameter1.AvailableValues.DisplayMember = "= Fields.Category"

Furthermore, I wanna bind this parameter to a objectdatasourse,,so I found this code but I could not use it


Public Sub HowToObjectDataSourceParameters()
    Dim objectDataSource1 As New Telerik.Reporting.ObjectDataSource()
    objectDataSource1.DataMember = "GetCars"
    objectDataSource1.DataSource = GetType(Cars)
    objectDataSource1.Parameters.Add(New Telerik.Reporting.ObjectDataSourceParameter("year", GetType(Integer), 2010))
    objectDataSource1.Parameters.Add(New Telerik.Reporting.ObjectDataSourceParameter("color", GetType(String), "=Parameters.Color"))
End Sub

objectDataSource1.DataSource = GetType(Cars)<>>>> what is Cars? <<>>what do they mean by this type,, i did not get it.

Thanks in advance
0
Steve
Telerik team
answered on 27 May 2011, 03:47 PM
Hi Anoop,

We see that you want to wire up the DataSourceParameter with a ReportParameter. It does not matter whether you're using SqlDataSource or ObjectDataSource Component. The code you've found in the Using Parameters with the ObjectDataSource Component help article is correct and is "using" the Cars class from the ListBound report example. You can open the demo reports locally and review the implementation.

Best wishes,
Steve
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Anoop
Top achievements
Rank 1
answered on 29 May 2011, 07:00 AM
Hi Steve,

Thanks a lot for your reply

What I need is sqlDatasource to retrieve the info of the parameter from the database,..

 

I tried the suggested code but it did not give me any intended result.

Where exactly should I place this codes?,, is there is any event for this to be run

 

See the report1 attached picture that what I get only the parameter is added without any data..

 

In report2 attached picture I used the Dynamic way to get the data >>that what I want using the code but I could not reach to it

 

 

Thanks a lot in advance

0
veena
Top achievements
Rank 1
answered on 29 May 2011, 06:29 PM
Anoop,

The way I used object datasource while using EF, by creating a function in class which fetches data from SQL server(in our case it was EDM). You must be using dataobject project or class in your solution, reference that class in the project where you have added reports. Add object datasouce and you should be able to navigate to the class and function, later add the parameters used in the function.
Tags
General Discussions
Asked by
Anoop
Top achievements
Rank 1
Answers by
Anoop
Top achievements
Rank 1
veena
Top achievements
Rank 1
Hrisi
Telerik team
Steve
Telerik team
Share this question
or