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

Suppressing Report Error Messages

3 Answers 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
almostEric
Top achievements
Rank 1
Iron
Iron
almostEric asked on 07 Jul 2015, 12:19 AM

I have a data structure where some fields may or may not be present. If the fields are not there, I just don't want to display anything. How do I suppress the 'object not found in this context' error message? There appears to be a thread that discussed this very issue, but the link to the answer has been deleted:

http://www.telerik.com/help/reporting/telerik.reporting-telerik.reporting.processing.renderingresult_members.html

 

 

3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 09 Jul 2015, 04:07 PM
Hi Eric,

In general, reports must be designed with fields existing in the data schema of the assigned data.
Invalid expressions errors can be caught in the report's Error event where you can work with the sender (processing item) and event stop the further processing of the report.

In order to provide you more accurate suggestion, please elaborate on the case when fields will be missing from the data supplied in the report.

Regards,
Stef
Telerik
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
almostEric
Top achievements
Rank 1
Iron
Iron
answered on 09 Jul 2015, 04:12 PM

It is a data structure where the objects the report displays are based on an interface, within the interface are the fields that are guaranteed to be present. the classes based on that interface will have additional properties. I'd like to display those properties if present, show nothing if not. Stopping the report from processing is *not* what I need.

Is there anything I can do in the ItemDataBinding event?

0
Stef
Telerik team
answered on 13 Jul 2015, 02:17 PM
Hi Eric,

Reports must be designed with the fields that will be available in the retrieved data. In a case where data schema will change, the reporting engine will not be able to evaluate the fields used in expressions, because these fields are not available in the report's DataSource.

My recommendation is to retrieve the data at run-time and check its schema, hide the report items which use fields not existing in the data schema, and set the data to the report. For example, let us assume we have a report that uses Fields.X and Fields.Y, and we retrieve data that has only X field in its schema:
//get data
var data = GetData();
 
//get a report instance
var report = new MyReport();
 
//modify the report definition
//get all TextBox items
var TBs = report.Items.Find(typeof(TextBox), true);
 
//analyze the data and modify the TextBox items respectively
  foreach (var tb in TBs)
                if ((tb as TextBox).Value.ToLower().Contains("fields.Y"))
                    (tb as TextBox).Value = "";
 
//set the data to the report
report.DataSource = data;
//or to a nested data item
(report.Items.Find("table1",true)[0] as Telerik.Reporting.Table).DataSource = data;
 
//display the report
var IRS = new InstanceReportSource { ReportDocument = report};
reportViewer1.ReportSource = IRS;


I hope this information helps you.

Regards,
Stef
Telerik
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
almostEric
Top achievements
Rank 1
Iron
Iron
Answers by
Stef
Telerik team
almostEric
Top achievements
Rank 1
Iron
Iron
Share this question
or