Trying to do a simple parameters report.....

2 Answers 41 Views
Filtering Rendering Report Parameters
Davide
Top achievements
Rank 1
Iron
Davide asked on 27 Jun 2023, 07:57 AM | edited on 28 Jun 2023, 06:40 AM

Hi i'm davide, in these days i'm working for a project that requires telerik on windows form c# desktop application.        So i'm trying to figure out what i need to do it but i don't find pretty much anything online, i can't find a solution please help me.

My little exercise consist in asking a year of school (1 to 5) to print only the ones students in that year, cvyear is a int from 0 to 5, I'M ITALIAN SO 1) ANNO = YEAR, classes is a type class, stu is a list of student. CODE:

string year = cvyear.ToString();
            var report1 = new Telerik.Reporting.Report();
            report1.DataSource = null;
            reportViewer1.ReportSource = null;
            var objectDataSource1 = new Telerik.Reporting.ObjectDataSource();
            objectDataSource1.DataSource = null;
            objectDataSource1.DataSource = classes.Stu;
            report1.DataSource = objectDataSource1;
            Telerik.Reporting.ReportParameter reportParameter1 = new Telerik.Reporting.ReportParameter();
            reportParameter1.Name = "yearParam";
            reportParameter1.Text = "Enter Value for year";
            reportParameter1.Type = Telerik.Reporting.ReportParameterType.Integer;
            reportParameter1.AllowBlank = false;
            reportParameter1.AllowNull = false;
            reportParameter1.Value = year;
           
            reportParameter1.Visible = true;
            
            reportParameter1.AvailableValues.DataSource = objectDataSource1;
            reportParameter1.AvailableValues.ValueMember = "= Fields.Anno";
  
            Telerik.Reporting.Filter filter1 = new Telerik.Reporting.Filter();
            filter1.Expression = "= Fields.Anno";
            filter1.Operator = Telerik.Reporting.FilterOperator.Equal;
            filter1.Value = "="+ year;
            

            Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
            reportSource.ReportDocument = report1;
            reportViewer1.ReportSource = reportSource;
            reportViewer1.ClearHistory();
            
            reportViewer1.RefreshReport();

 

2 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 29 Jun 2023, 11:27 AM

Hi Davide,

Thank you for the provided information!

Please note that creating reports purely from code is not recommended. I highly suggest one of our report designers instead - Report Designer Tools at a Glance - Telerik Reporting.

I created a sample report, that I believe fits your scenario, with the Standalone Report Designer and have attached it to my reply, please have a look and let me know if you have any questions.

Also, if you are new to Telerik Reporting, please make sure to have a look at the Step-by-Step Guide on Designing Telerik Reports - Telerik Reporting article to get a good idea of how the attached report works.

Regards,
Dimitar
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
0
Davide
Top achievements
Rank 1
Iron
answered on 29 Jun 2023, 01:04 PM | edited on 29 Jun 2023, 01:10 PM

 

Hi dimitar,

thank u for you reponse, actually i used the report designerfor the structure of the report that i connected to my database, the report in the code that i sent is reportViewer1.

in the rest of the code i have created a parameter and a filter, i wanted to add all these stuff in my reportViewer1 but i've tried for 2 days without succed in. It's true that i've watched only seen people do it with web application but i'm using it for desktop one. how can i give you more information?

 

Dimitar
Telerik team
commented on 04 Jul 2023, 09:00 AM

Hi Davide,

In the code above, you create a brand new report at the very beginning - var report1 = new Telerik.Reporting.Report();, so you are not actually using the report that you have created with the designer.

If you have used the Standalone Report Designer, you need to unpackage the report and then use the create report object to edit it before wrapping it in an InstanceReportSource - Packaging Report Definitions Explained - Telerik Reporting.

If you have used Visual Studio Report Designer, then you would need to initialize your custom class instead of unpackaging: var report1 = new MyReport():  

For more information, you may have a look at the Managing Reports with code - Telerik Reporting articles, hope that will help.

Let me know if you have additional questions.

Tags
Filtering Rendering Report Parameters
Asked by
Davide
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Davide
Top achievements
Rank 1
Iron
Share this question
or