I have a generate a PDF report from data I am getting from web service. Based on some certain conditions, the data can be nested where schema is changed in both tables. The problem is when I try to add the nested table, it basically creates 2 set of tables, First it adds the main table and below this table, all child table rows are added together. My code is as:
//add cell for rowfor (var i = 0; i < props.Length; i++){ if (props[i].Name == "ChildGrid" && gridCols[i].ChildGridColumns.Length > 0) { var childGrid = item?.GetType().GetProperty("ChildGrid")?.GetValue(item, null); if (childGrid != null) { IEnumerable lst = ((IEnumerable)childGrid).Cast<object>().ToList(); AddChildGridToReport(lst, gridCols[i].ChildGridColumns); } } else { var dt = props[i].GetValue(item, null);
//update class code with new value if (ReportFor == "Consist/Inventory" && props[i].Name == "ClassCode") clsCode = dt?.ToString();
AddGridRowCell(tableRow, props[i], dt?.ToString(), gridCols[i], cellPattern); }}
private void AddChildGridToReport(object itemList, ColumnProperties[] gc = null){ //table IGrid table = section.AddGrid(); table.Borders = bordersStyle; table.Width = new RelativeWidth(100);
IGridRow tableRow; Background cellBgColor = new Background(Colors.White); Background cellAltBgColor = new Background(new Color(252, 252, 252)); int j = 0;
IGridHeader header = table.Header; header.Repeat = true; for (var i = 0; i < gc.Length; i++) { IGridColumn gridCol = table.AddColumn(); gridCol.Width = new RelativeWidth(gc[i].Width);
AddGridHeader(header, gc[i]); }
//define cell pattern/style GridCellPattern cellPattern = new GridCellPattern() { Paddings = cellPaddings, Borders = bordersStyle, }; cellPattern.Alignment.Vertical = Alignment.Middle;
//convert object to IEnumerable var items = (IEnumerable)itemList; foreach (var item in items) {
PropertyInfo[] props = item.GetType().GetProperties();
tableRow = table.AddRow(); cellPattern.Background = (j % 2 == 0) ? cellBgColor : cellAltBgColor;
for (var i = 0; i < props.Length; i++) { //AddRowCell(tableRow, cellBackgroundColor, gc[i], props[i]); var dt = props[i].GetValue(item, null); AddGridRowCell(tableRow, props[i], dt.ToString(), gc[i], cellPattern); } j++; }}
Hello Sarojanand,Can you please share a little more details on your scenario:- Are you using the Infragistics Reporting which creates an .igr file for the report? - Which is the platform you are working with? - Which version of the Infragistics product you are using?Thank you.
Hi Maria,
I am using "http://www.igniteui.com/help/documentengine-writing-reports" which gives you option to generate report in PDF or XPF format. The application is being developed in .Net/C# 5.0. I am using 2014.1 version.
Let me know if you need any more details.
Hello Sarojanand,
From what I see you're adding the nested table to the section object.Try adding a Grid to the cell like this:
innerGrid = gridCell.AddGrid();
Hope this helps,Martin PavlovInfragistics, Inc.
Thanks Martin,
That worked fine. I was added grid again in the "section", thats why it was adding them in the bottom.
You're welcome. I'm glad that I was able to help. Let me know if you have further questions regarding this scenario.
Best regards,Martin PavlovInfragistics, Inc.