Hi,
I'm using SL4 and Telerik Reporting with the latest components from Q1 2011!
From the other threads I used the mechanism to directly print reports
without first showing them within ReportViewer:
private void button1_Click(object sender, RoutedEventArgs e)
{
var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
var viewerModel = (ReportViewerModel)layoutRoot.DataContext;
viewerModel.ApplyReportParametersCommand.Execute(null);
viewerModel.PrintReportCommand.Execute(null);
}
Always the first time the parameter is not applied.
The mechanism for that is:
private void ReportViewer1_RenderBegin(object sender, RenderBeginEventArgs args)
{
args.ParameterValues["Parameter1"] = textBox1.Text;
}
The Xaml-Code:
<telerik:ReportViewer Grid.Row="1" x:Name="ReportViewer1"
Width="1000" UseNativePrinting="False"
telerikControls:StyleManager.Theme="{Binding SelectedItem, ElementName=ThemeSelector}"
ReportServiceUri="../ReportService.svc"
Report="ClassLibrary1.Report1, ClassLibrary1" RenderBegin="ReportViewer1_RenderBegin" />
When I make the ReportViewer big enough to observe I can see that the report is rendered
correctly even the first time!
But the printed document has only the report skeleton missing the real data.
From the second call on (button click) the parameter will be applied and its is working fine.
If I toggle the UseNativePrinting to true (the new default) it works also the first time.
Unfortunately I will need the UseNativePrinting=false option to get the reports with landscape-mode
immediately ready to print.
Please help me!
It is urgent since it should have been a fast switch from the old Q2 2010 Reporting.components
to the latest version and I have to deploy immediately.
Best Regards
Andrew
6 Answers, 1 is accepted
With this option it uses the parameters but always returns only the first page from the report: strange thing!
Whithin the debugger (UseNativePrinting = false) I can see that the parameter values are empty the first time.
The second time I call the print method they are filled.
Please help!
Regards
Andrew
Executing the print command is the same as clicking the viewer's print button. Additionally when UseNativePrint is set to False we call again the RenderBegin handler and process a new report instance. However we have made some tests locally with the provided code and description but we are unable to reproduce the unexpected behavior. Check out the attached video and sample project. If you still experience any difficulties we will highly appreciate if you open a support thread and send us a sample project that exhibits the issue to debug locally.
Best wishes,
Peter
the Telerik team
thank you for your reply.
Your sample application is a little bit too simple.
Please make one more test - it will take you approximately 2 minutes!
Insert a TextBox in the Xaml-Code and modify the RenderBegin in the code behind from your static parameter value:
private void ReportViewer1_RenderBegin_3(object sender, RenderBeginEventArgs args)
{
args.ParameterValues["Parameter1"] = "render begin value";
}
to a dynamic case where you retrieve the parameter from the value in the TexBox:
private void ReportViewer1_RenderBegin_3(object sender, RenderBeginEventArgs args)
{
args.ParameterValues["Parameter1"] = _parValueTextBox.Text;
}
Then you will notice that after clicking the button the ReportViewer shows the correctly rendered document
with the current value from the TextBox. Ok!
But please print out the document and you will notice that the printed document does not show the current value
from the TextBox. Instead it shows always the value from the last time.
You can change the TextBox value again and again and the printed document is always one step behind.
Please check this one more time.
I get crazy about it.
I have made so many tests and approaches to initialize the values in any kind but nothing seems to work.
Regards
Andrew
We have reproduced the described behavior when a Textbox control is used to provide values for report parameters. Generally this is expected because we are using the already rendered report as a base for the print document. Thus when the PrintReportCommand is called in your code, the report is not refreshed yet. To avoid this behavior you have to wait the ApplyReportParametersCommand to refresh the report as shown in the following code snippet:
public partial class MainPage : UserControl, IReportServiceClientFactory
{
bool printFlag;
public MainPage()
{
InitializeComponent();
this.ReportViewer1.ReportServiceClientFactory = this;
printFlag = false;
}
ReportViewerModel viewModel;
ReportViewerModel ViewerModel
{
get
{
if (viewModel == null)
{
var layoutRoot = (FrameworkElement)VisualTreeHelper.GetChild(this.ReportViewer1, 0);
viewModel = (ReportViewerModel)layoutRoot.DataContext;
}
return viewModel;
}
}
public ReportServiceClient Create(Uri remoteAddress)
{
var serviceClient = new ReportServiceClient(remoteAddress);
serviceClient.RenderAndCacheCompleted += new EventHandler<
RenderAndCacheEventArgs
>(serviceClient_RenderAndCacheCompleted);
return serviceClient;
}
void serviceClient_RenderAndCacheCompleted(object sender, RenderAndCacheEventArgs e)
{
if (printFlag)
{
ViewerModel.PrintReportCommand.Execute(null);
}
printFlag = false;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
ViewerModel.ApplyReportParametersCommand.Execute(null);
printFlag = true;
}
private void ReportViewer1_RenderBegin_3(object sender, RenderBeginEventArgs args)
{
args.ParameterValues["Parameter1"] = textBox1.Text;
}
}
Steve
the Telerik team
cool!
It works!
I've expected something similar already.
So this saves my weekend and finishes a week full of pain.
Thank you!
Best Regards
Andrew
Is there any improvements on printing without the report viewer in progress?