views:

265

answers:

2

Hello there.

I am using vs2008 with CrystalReports and I'm wandering how can i dynamically add rows of data to a *.rpt file?(using c#).

In more detail i want to create a a function that populates a *.rpt file with data that might contain lists(for example "FirstName", "LastName", List<"Friend"> ;..Friend beeing an object that contains multiple fields like "FriendNr", "Address",....).

the code that i used so far is:

        ReportDocument rpt = new ReportDocument();
        MemoryStream stream = new MemoryStream();
        string filename = filepath + "/myRpt.rpt";
        rpt.Load(filename);            

        rpt.SetParameterValue(0, myObject.FirstName);
        rpt.SetParameterValue(1, myObject.LastName);

Inside the rpt file i have placed FieldObjects(Parameter Fields), and i populate the file with data by assigning the desired values to these objects (" rpt.SetParameterValue(0, myObject.FirstName);" )

Please help me find a way to populate the report with the rows of data contained in the List also.

Thanks a lot for your time.

+1  A: 

I don't think it is possible to add data rows to a report this way. I suggest using a Typed DataSet as your report data source. The report can then display as many Friend objects as you require.

Ray
+1  A: 

Dynamic 'rows' approaches:

1). You could add more items to the parameter's CurrentValues collection. Not sure how you are using this in the report, but it may work for your purposes. Look at the ParameterFieldDefinition class for more information.

2). Create a DataSet, modify as necessary, then assign it to the report. Use the ReportDocument.SetDataSource() method to bind a report to data programmatically.

3). Another approach is to build a report that uses XML data, then programmatically modify the XML, then refresh the report.

Craig