Report with dynamic tables

Aug 6, 2009 at 9:24 AM

Hi hanswolff,

We have decided to use the WPF Reporting Engine project in one of our projects.

We have a request which i guess it could be useful to add to the project. Currently we have implemented it on a dirty way, but we would like to use the trunk version of the open source project in the coming years.

We need to create reports of dynamic tables, that means that the column definition could be modified on execution time.

The final Xaml file would be something like:


<TableRowGroup Style="{StaticResource headerFooterRowStyle}">
                    <xrd:TableRowForDynamicHeader TableName="Header"/>                                                          
                <TableRowGroup Style="{StaticResource dataRowStyle}">
                    <xrd:TableRowForDynamicDataTable TableName="Data"/>                    



The implementation of the ReportPaginator(dirty/fast way):



foreach (ITableRowForDynamicDataTable iTableRow in dynamicDataTableRows)
                TableRow tableRow = iTableRow as TableRow;
                if (tableRow == null) continue;

                TableRowGroup tableGroup = tableRow.Parent as TableRowGroup;
                if (tableGroup == null) continue;

                TableRow currentRow = null;

                DataTable table = _data.GetDataTableByName(iTableRow.TableName);

                for (int i = 0; i < table.Rows.Count; i++)
                    currentRow = new TableRow();

                    DataRow dataRow = table.Rows[i];
                    for (int j = 0; j < table.Columns.Count; j++)
                        string value = dataRow[j].ToString();
                        currentRow.Cells.Add(new TableCell(new Paragraph(new Run(value))));

            foreach (ITableRowForDynamicHeader iTableRow in dynamicHeaderTableRows)
                TableRow tableRow = iTableRow as TableRow;
                if (tableRow == null) continue;

                DataTable table = _data.GetDataTableByName(iTableRow.TableName);

                foreach (DataRow row in table.Rows)
                    string value = row[0].ToString();
                    TableCell tableCell = new TableCell(new Paragraph(new Run(value)));




Looking forward hearing about the request.


Best regards and many thanks.

José Cano

Oct 2, 2009 at 2:13 PM

Jose: I'm interested in your solution also.

The big percentage of the report will have the same template, only changing the tables.

Since I'm new to the project, Do you have more insights in real world use of the project?


Oct 2, 2009 at 2:36 PM

Hi Eddy,


We are currently using this feature in order to create a generic report to print the view of list view reports.


We used a command to call the report engine, and we pass to the command the required parameters from the view (xaml)


                                Command="{x:Static PrintUserControl.PrintDynamicListViewCommand}" >
                                <MultiBinding Converter="{StaticResource multiParameterConverter}">
                                        <Binding ElementName="listView"/>
                                        <Binding Path="Titulo"/>

On the command, we take the Items of listView and create the required ReportData

GridView gridView = listView.View as GridView;

tableHeader = new DataTable("Header");
tableData = new DataTable("Data");
foreach (GridViewColumn column in gridView.Columns)
                    tableHeader.Rows.Add(new object[] { column.Header.ToString() });

foreach (object item in listView.Items)
............. fill up tableData depending on your business logic

ReportData data = new ReportData();

In order to get it working, you have to modify ReportPaginator with the lines described on the post above.

I hope it helps.

Oct 2, 2009 at 3:05 PM

Hello guys,

Thank you for your contributions! I'm really busy at the moment and cannot continue the development for now. :-( If you think you have good ideas feel free to improve the reporting engine.

@ppcanodehuelva: I added you to the team, would you please add your suggested changes to the source code?



Oct 2, 2009 at 6:42 PM

Jose: yes, it helps a lot. Thanks!