Report Viewer – Object With Nested List Objects-Collection of common programming errors
I have an existing class structure in place and want/need to use that as a data source for a series of reports using vb and 2005, (though we are almost ready to move to 2010, so if that will solve this ill move today!)
Using gotreportviewer sample for nested objects ive added a reportmanager class exposing a getdata method which ive populated with all my data and returned a list(of object). the data is there and correct at the point of databinding, i can add and reference top level properties, however not matter what syntax i try i cant reference the fields in nested classes/lists. I get various messages ranging from “#Error” in the ouput field to nothing, to wont compile.
my class structure is roughly this in short form:
Assembly0
Class ReportManager
TheData as List(Of Object)
New() 'that populates TheData from the class structure below
GetData() as List(of Object)
Assembly1
Class Test
aProperty1 as String
aProperty2 as Int
aProperty3 as String
aProperty4 as String
aProperty4 as List(of aType1)
Assembly2
Class AaType1
aProperty1 as String
aProperty2 as Int
aProperty3 as String
aProperty4 as String
aProperty4 as List(of aType2)
aProperty4 as List(of aType3)
aProperty4 as String
Assembly3
Class aType2
aProperty1 as Boolean
aProperty1 as String
you get the idea
and so on.....
in my main app
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create an instance of our ReportManager Class
Try
' trust assemblies used in get data
ReportViewer1.LocalReport.ExecuteReportInCurrentAppDomain(Assembly.GetExecutingAssembly().Evidence)
ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("assy1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234")
ReportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("assy2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234")
' etc through ALL dependant assemblies
' create datamanager, that will populate its TheData property
Dim reportMan As Data.Reporting.Manager = New Data.Reporting.Manager(18) ' test id sent
' this is the method from the gotreportviewer sample, which only allows you to reference top level properties, regardless of syntax used. i.e. =Fields!Prop.Value.SubProp
' doesnt work
'ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DummyDataSource", reportMan.GetData))
'Me.ReportingDataBindingSource.DataSource = reportMan.GetData
' this is the only method i have found that allows me to reference an objects nested property and its fields.....?
Data = reportMan.GetData()
Me.ReportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Data_Reporting_ReportingData", Data))
' fortnatley there is only ever one test in the list, HOWEVER there will be 4 specimens and n stages below that and so on..
Dim SpecimenData As SpecimenList = Data(0).Specimens
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Tests_Specimen", SpecimenData))
' so this method is no good either. currently only a test its just returning the first specimen.
'Dim StageData As Tests.Stages = Data(0).Specimens(0).Stages
'Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Tests_Specimen", SpecimenData))
' render report
Me.ReportViewer1.RefreshReport()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Fixes i found online/googling:
-
You must add “ExecuteReportInCurrentAppDomain”, done that no difference.
-
You must add Assembly: AllowPartiallyTrustedCallers() to AssemblyInfo.vb, No difference.
-
You must strongly name you dependant assemblies, done that and it did get rid of an error regarding a call being made in the “Code” property of the report (for localization).
-
have tried the =Fields!Property.Value.SubProperty syntax and it DOESNT work! no matter what variation i try.
‘ in the rdlc – this syntax works for a top level properties
=Sum(Fields!TestVersion.Value, “Data_Reporting_ReportingData”)‘ using the alternate method list in the above code this works
=First(Fields!Index.Value, “Tests_Specimen”)‘ but these dont for its child properties =First(Fields!Specimens.Value.Index, “Data_Reporting_ReportingData”) =Fields!Specimens.Value.Index
=Fields!Specimens.Value.Index.Value
so does that mean im goin got have no choice but create something like Dim SpecimenData As Tests.SpecimenList = Data(0).Specimens for every single nested object? also for obvious reasons id rather not have to flatten the entire datastructure as its massive.
I have tried everything i can find on this, not much out there and everything points back to the same three four articles/blog posts that just arent working for me, thier samples unmodified work, but none of them work when applied to nested lists or nested objects of inherited list types.
Does anyone have any sample code of using objects with nested lists that actually works? as none of the ones i could find online work with anything but the simplest of scenarios. i.e. one assembly, or one code file or no nested lists or simple/native types.
ive been at this the best part of A WEEK! im now bald and stressed please help.
Failing that can anyone suggest a thrid party vendor that does support this sort of thing? does crystal? pebble?
appologies for the wall of text… Matma