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

Dynamic Table NullReferenceException

3 Answers 158 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mathew
Top achievements
Rank 1
Mathew asked on 20 Feb 2012, 06:37 PM
I'm using Telerik Reporting 2010 Q3, with the Silverlight ReportViewer. 

I've created a static function for adding a column to a report table using this Sample Project as a starting point. Everything is working great except for export. If I generate a different report, and then generate one of the two reports with dynamic columns I get an ArgumentOutOfRangeException followed by a NullReferenceException when I export. If I re-Generate the report with the dynamic columns then the export works correctly.

Here is what's printed to the output window: 

*** ProcessReport #0 STARTED ***


*** Report Processing STARTED ***


*** Table::ProcessItem STARTED ***


*** TableBuilder::AddColumns STARTED ***
A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
*** TableBuilder::AddColumns DONE in 00:00:00.0248971 ***


*** Table::ProcessItem DONE in 00:00:00.0295418 ***


An exception has occurred while processing '' item:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at Telerik.Reporting.Processing.Data.DataMember.<GetMembers>d__12.MoveNext()
   at Telerik.Reporting.Processing.TableBuilder.WalkHierarchy(Boolean isColumnGroup, IList`1 hierarchy, DataMember parentData, Single distance, AddBodyLineCallback addBodyLineCallback, AddPresentationCallback addPresentationCallback, Int32 startIndex, Boolean parentCollapse, Single& collapsePresentationCorrection, Single& mergePresentationCorrection, Int32& mergePresentation)
   at Telerik.Reporting.Processing.TableBuilder.Fill(Table table)
   at Telerik.Reporting.Processing.Table.ProcessItem()
   at Telerik.Reporting.Processing.ReportItemBase.Process(DataMember data)

Any ideas?

3 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 21 Feb 2012, 11:15 AM
If it gives you error only if another report has been generated before, this means that you are doing something that depends on the previous report. To create a dynamic report it is best to get the data schema then change the report definition (not mess with the processing item while it is being processed because there you can't really know what you are doing there) and after you have created a new, modified report instance you process it.

Another thought: You are adding an extra column if needed. Why don't you just create another report with the extra column, and keep the original one at the same time. Instead of dynamically changing the report, you will switch between the reports.
 
0
Mathew
Top achievements
Rank 1
answered on 21 Feb 2012, 05:15 PM
Hey Hadib,

Thanks for the reply.

I am modifying the table definition. I've also made the function I was using local to each report.

I've taken the code to add a generic function from this project, with two changes on my end:
  1. I am able to construct the table in the constructor using a cache I get from the database
    1. I have noticed that changes outside of the InitializeComponent function don't make it to the exported pdf (Maybe this is an underlying problem?), which is one of the reason's I build the table from cache in the InitializeComponent function.
    2. I pulled everything out of the for loop and moved it into an AddColumn function.

I also get the error the first time I run a report with the dynamic table, so it only works after I run the report twice.

The dynamic tables I'm creating have 1-2 static columns on either end, and 1-n dynamic columns in between them. I thought dynamic columns made more since creating these tables, but I am open to suggestions. They do need to appear to the user to be a single table.

I'm really trying to determine if upgrading the Telerik Reports will resolve this issue, or if I'm just doing something wrong that is causing the error. Since the error occurs in the Telerik dll I really can't tell what's breaking.

0
Hadib Ahmabi
Top achievements
Rank 1
answered on 22 Feb 2012, 02:35 PM
Try to serialize the report - once on the first processing and once on the second. This might help you spot a difference between the first and the second run.
http://www.telerik.com/help/reporting/programmatic-xml-serialization.html 

You said: "I have noticed that changes outside of the InitializeComponent function don't make it to the exported pdf" - this is definitely not true. I modify report definitions after the InitializeComponent method all the time.

Here's a method I have used to generate a column. Important - when creating the new textboxes make the exatcly the same size as the rest so they fit. I've had troubles with that. This method called after the InitializeComponent with a proper index value creates another column to the standard table (one body row, one header row). Of course you have to modify the sizes to fit your table.
public static void AddColumn(Table table, int index)
{
 
    var textBoxH = new Telerik.Reporting.TextBox();
    textBoxH.Name = "textBoxH";
    textBoxH.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(0.6701388955116272D), Telerik.Reporting.Drawing.Unit.Inch(0.921875D));
    textBoxH.Value = "BBB";
 
    var textBoxB = new Telerik.Reporting.TextBox();
    textBoxB.Name = "textBoxH";
    textBoxB.Size = new Telerik.Reporting.Drawing.SizeU(Unit.Inch(0.6D), Unit.Inch(0.9D));
    textBoxB.Value = "BBB";
 
    Telerik.Reporting.TableGroup tableGroup1 = new Telerik.Reporting.TableGroup();
    tableGroup1.ReportItem = textBoxH;
    table.ColumnGroups.Add(tableGroup1);
 
    table.Body.Columns.Add(new Telerik.Reporting.TableBodyColumn(Unit.Inch(0.7D)));
 
    table.Body.SetCellContent(0, index, textBoxH);
    table.Body.SetCellContent(1, index, textBoxB);
 
    table.Items.Add(textBoxH);
    table.Items.Add(textBoxB);
}
Tags
General Discussions
Asked by
Mathew
Top achievements
Rank 1
Answers by
Hadib Ahmabi
Top achievements
Rank 1
Mathew
Top achievements
Rank 1
Share this question
or