Using a list of Objects as a RecordSet
Any object that implements IEnumerable can be used as the data source for creating a report. This would allow users to use their own custom list of objects as a data source for creating DynamicPDF reports. This would also allow anyone retrieving a list of objects using LINQ programming to work directly with those objects as the recordset to create your PDF report.
The query within the DPLX file should be specified as Event Driven and then the custom list can be passed into the Reports OpeningRecordSet event. That will then be the data used to output the PDF report. Illustration 1 shows a very simple DPLX file with just two RecordBoxes with Values "Number" and "Text". The Query for the Report is also shown in Illustration 1 as "Event Driven".

Illustration 1 - A Sample DPLX file for defining a custom IEnumerable List as a RecordSet.
A simple example below show how to code an event handler for the OpeningRecordSet event of the the Query object to define a new EnumerableRecordSet object out of an ArrayList of custom objects. That EnumerableRecordSet will be the RecordSet argument to use for creating the PDF. The public properties "Number" and "Text" from the CustomObj below correspond to the two RecordBoexes defined in the DPLX file.
public void CreateRecordSetExample()
{
DocumentLayout report = new DocumentLayout( filePath );
Query query1 = report.GetQueryById( "Query1" );
query1.OpeningRecordSet += new OpeningRecordSetEventHandler( Query_OpeningRecordSet );
Document document = report.Run();
document.Draw( @"C:\Temp\report.pdf" );
}
private void Query_OpeningRecordSet( object sender, OpeningRecordSetEventArgs e )
{
ArrayList objectList = new ArrayList();
objectList.Add(new CustomObj(1, "One"));
objectList.Add(new CustomObj(2, "Two"));
objectList.Add(null);
objectList.Add(new CustomObj(3, "Three"));
objectList.Add(new CustomObj(4, "Four"));
args.RecordSet = new EnumerableRecordSet(objectList);
}
public class CustomObj
{
private int number;
private string text;
public TestObj(int number, string text)
{
this.number = number;
this.text = text;
}
public int Number
{
get { return number; }
}
public string Text
{
get { return text; }
}
}
Public Sub CreateRecordSetExample()
Dim MyReport As New DocumentLayout(MyFilePath)
Dim MyQuery As Query = MyReport.GetQueryById("Query1")
AddHandler MyQuery.OpeningRecordSet, AddressOf Query_OpeningRecordSet
Dim MyDocument As Document = MyReport.Run()
MyDocument.Draw("C:\Temp\report.pdf")
End Sub
Private Sub Query_OpeningRecordSet(ByVal sender As Object, ByVal e As OpeningRecordSetEventArgs)
Dim MyObjectList As New ArrayList()
MyObjectList.Add(New CustomObj(1, "One"))
MyObjectList.Add(New CustomObj(2, "Two"))
MyObjectList.Add(Nothing)
MyObjectList.Add(New CustomObj(3, "Three"))
MyObjectList.Add(New CustomObj(4, "Four"))
args.RecordSet = New EnumerableRecordSet(MyObjectList)
End Sub
Public Class CustomObj
Private MyNumber As Integer
Private MyText As String
Public Sub New(ByVal number As Integer, ByVal text As String)
Me.MyNumber = number
Me.MyText = text
End Sub
Public ReadOnly Property Number() As Integer
Get
Return MyNumber
End Get
End Property
Public ReadOnly Property Text() As String
Get
Return MyText
End Get
End Property
End Class