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

DataGrid.SelectedItems as DataSource for Telerik Report

14 Answers 101 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
JOSE
Top achievements
Rank 1
JOSE asked on 16 Nov 2016, 06:38 PM

I have a DataGrid in a user control of my WPF app, and I want when the user selects some rows from here, send DataGrid.SelectedItems as DataSource to my Telerik Report, and I don't know how i can do this, somebody have an example to help me?

 

14 Answers, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 17 Nov 2016, 04:24 PM
Hello Jose,

You can use a custom function to save the values selected from the DataGrid and use this function to set the report's DataSource property via bindings.

Check User functions help article and let us know if you need any additional information.


Regards,
Katia
Telerik by Progress
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
0
JOSE
Top achievements
Rank 1
answered on 17 Nov 2016, 05:37 PM

Thank you so much Katia, but, my telerik report only print a bar code for a idprod and her description, is a label product print, and I want to send to the report an array or list or any IEnumerable with all idprod and her description previouslly selected by the user, and in the telerik report no use any DataSource, because I don't want to Access the data base again to get the same data if I can send it as parameter...I don't know if I can explain myself...

I want to send:

23458 Air filter

25478 Diesel filter

26878 Transmission oil

and I need to print for each a label with code bar for the idprod, and description....

0
JOSE
Top achievements
Rank 1
answered on 17 Nov 2016, 09:55 PM

I attach a images related.

Right now Works, but the report is called for each product selected, and show me the printer window for every one

0
Katia
Telerik team
answered on 21 Nov 2016, 12:22 PM
Hello Jose,

Instead of iterating over the collection of grdProductos.SelectedItems and adding a new parameter for each of the items, you can set the report.DataSource property directly to grdProductos.SelectedItems.

To access the DataSource property of the report, create a new instance of rpEtiqueta report. After the data is passed to report.DataSource, set the modified report as ReportDocument of InstanceReportSource.

As the data source is not available during design-time, the data fields must be typed in manually (= Fields.pIDProd) or you can use the approach described in Working With Data at Design Time(Data source available only at runtime) help article.


Regards,
Katia
Telerik by Progress
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
0
JOSE
Top achievements
Rank 1
answered on 22 Nov 2016, 04:11 PM
Thanks Katia, but I'm sorry, this is my first telerik report in WPF (I did 2 in Silverlight before) and I don't understand how I can do:

"To access the DataSource property of the report, create a new instance of rpEtiqueta report. After the data is passed to report.DataSource, set the modified report as ReportDocument of InstanceReportSource."
 :(
0
JOSE
Top achievements
Rank 1
answered on 22 Nov 2016, 07:51 PM

I got it, I think, I made:

Report rpt = new rpEtiquetaProductos();
rpt.DataSource = grdProductos.SelectedItems;
ReportViewer1.ReportSource = rpt;      // <-BUT HERE SAY ME IS OBSOLETE ?
ReportViewer1.PrintReport();

But now Works as I need

0
Accepted
Katia
Telerik team
answered on 23 Nov 2016, 09:53 AM
Hello Jose,

Setting the viewer's ReportSource directly to a report instance is obsolete as of Q2 2012 - How to migrate your project to utilize the new ReportSource objects.
The new approach is to use a ReportSource object to set the viewer's ReportSource, for example:
Report rpt = new rpEtiquetaProductos();
rpt.DataSource = grdProductos.SelectedItems;
 
Telerik.Reporting.InstanceReportSource instanceReportSource = new  Telerik.Reporting.InstanceReportSource();
instanceReportSource.ReportDocument = rpt;
ReportViewer1.ReportSource = instanceReportSource;


Regards,
Katia
Telerik by Progress
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
0
JOSE
Top achievements
Rank 1
answered on 24 Nov 2016, 02:49 PM

ooohhhhh, ok, perfect, I made the change right now, thank you so much Katia

Regards

0
JOSE
Top achievements
Rank 1
answered on 06 Dec 2016, 02:45 PM

No Katia, I made the change but,in the tests, when I select 6 products, it only show me 4, then in another test show me 0, I think some thing is wrong but I don't know what, please help me!!

When I'm in the telerik report designer, I defined a SQL Data Source in wich I read the Products table, and in my user control of WPF asigned to the report the DataSource with the products selected by the user, but don't work

 

0
JOSE
Top achievements
Rank 1
answered on 06 Dec 2016, 02:46 PM

No Katia, I made the change but,in the tests, when I select 6 products, it only show me 4, then in another test show me 0, I think some thing is wrong but I don't know what, please help me!!

When I'm in the telerik report designer, I defined a SQL Data Source in wich I read the Products table, and in my user control of WPF asigned to the report the DataSource with the products selected by the user, but don't work

 

0
Katia
Telerik team
answered on 07 Dec 2016, 12:57 PM
Hello Jose,

Test switching to Print preview in the Designer or in the WPF Report Viewer - Interactive vs. Print Layout.

Also, check if the report has any filters applied and test modifying the filter expression.

To provide you more accurate suggestions we would need to check a sample project reproducing the issue and demonstrating your current setup.


Regards,
Katia
Telerik by Progress
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
0
JOSE
Top achievements
Rank 1
answered on 07 Dec 2016, 02:51 PM
No Katia, I had already checked that there was no filters, and the preview is from the designer, if I go to send the DataSource from the instance report in WPF, how I must defined the report DataSource at the designer? I defined a temporary SQLDataSource point to the Products Table, without filters, is this correct?
0
JOSE
Top achievements
Rank 1
answered on 07 Dec 2016, 04:40 PM
Katia, please excuse me, excuse me, excuse me, but at beggining I was printing product by product, using the Report Parameters, and I don't remember when I add a Filter to test, and yes, this was the problem, I deleted the filter and now works fine, thank you so much
0
Katia
Telerik team
answered on 08 Dec 2016, 08:20 AM
Hello Jose,

No problem at all. I am glad that you discovered the cause of the issue.

Let us know if any other questions come up.


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