Report Viewer - Object With Nested List Objects
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.ExecuteReportInCurrentAppDoma开发者_开发知识库in(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 dependent 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 DOESN'T 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.ValueSo does that mean I have no choice but to create something like Dim SpecimenData As Tests.SpecimenList = Data(0).Specimens for every single nested object? Also for obvious reasons I'd rather not have to flatten the entire datastructure as it's 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 aren't working for me, their 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.
I've been at this the best part of A WEEK! I'm 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?
Apologies for the wall of text... Matma
I´m Looking for almost the same, except, that I have objects that have as property other objects, no List of objects, any way, you asked if Crystal Reports do this kind of thing, YES IT DOES, it´s a little bit difficult to do it, but it does.
I don´t know why it´s so difficult to work with that kind of think on now days. Because we are aways working with persistance Frameworks, like Entity Framework, and others, so, you do a hell of a job with a Persistance, and when you go to reports, you need to back to your DataBase model if you want easy work! So waste of time!
I Just have found, it´s possible to do it in report viewer, But it had a problem in visual studio 2010, it´s fixed in SP1 but you need to set all your classes that are used as nested objects as Serializable
Please read : http://wraithnath.blogspot.com.br/2011/04/reportviewer-object-datasource-nested.html
精彩评论