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

Object reference not set as an instance of an object

2 Answers 179 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
JOSE
Top achievements
Rank 1
JOSE asked on 24 Apr 2017, 06:56 PM

What is wrong??? if the user select send to print first, show this error "Object reference not set as an instance of an object"
But if first sent to the screen, and then select send to the printer, there no problem ????

I Attach my code

2 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 25 Apr 2017, 03:28 PM
Hi Jose,

The code uses the viewer to print. The viewer's ReportSource must have been set and the report must have been processed and rendered with the information provided through the ReportSource.

You need to check if the viewer's ReportSource is set and if the report rendering is ended (RenderingEnd event) at the time the print operation is called.


I hope this helps.

Regards,
Stef
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
Accepted
JOSE
Top achievements
Rank 1
answered on 27 Apr 2017, 01:06 PM

Thank you Stef

My solution was:

var TRS = new TypeReportSource();
TRS.TypeName = typeof(rpRMEIndustriales1).AssemblyQualifiedName;
TRS.Parameters.Add(new Telerik.Reporting.Parameter("pFiltros", Filtro));
TRS.Parameters.Add(new Telerik.Reporting.Parameter("pBase", ((BaseCL)cbBase.SelectedItem).Base));
TRS.Parameters.Add(new Telerik.Reporting.Parameter("pFechaIni", FechaIni));
TRS.Parameters.Add(new Telerik.Reporting.Parameter("pFechaFin", FechaFin));
TRS.Parameters.Add(new Telerik.Reporting.Parameter("pBaseDesc", ((BaseCL)cbBase.SelectedItem).Nombre));
TRS.Parameters.Add(new Telerik.Reporting.Parameter("pConcentrado", chkConcentrado.IsChecked));
ReportViewer1.ReportSource = TRS;
if (rbToScreen.IsChecked == true)
{
    ReportViewer1.RefreshReport();
    stkReportView.Visibility = System.Windows.Visibility.Visible;
}
else
{
    System.Windows.Forms.PrintDialog printDlg = new System.Windows.Forms.PrintDialog();
    printDlg.AllowSomePages = true;
    printDlg.AllowCurrentPage = false;
    printDlg.UseEXDialog = true;
    DialogResult result = printDlg.ShowDialog();
    // If the result is OK then send the document to the printer
    if (result == DialogResult.OK)
    {
        ReportProcessor reportProcessor = new ReportProcessor();
        reportProcessor.PrintReport(TRS, printDlg.PrinterSettings);
    }
}

Tags
General Discussions
Asked by
JOSE
Top achievements
Rank 1
Answers by
Stef
Telerik team
JOSE
Top achievements
Rank 1
Share this question
or