Current filter:
                                You should refresh the page.
                                  • Hi there,

                                    I have a requirement to create a report with a variable number of columns. This data is stored in a list of objects like:

                                    public class AvgDowntimeRowObject { // Constructors ======================================================= public AvgDowntimeRowObject() { Downtimes = new List<decimal>(); } // Properties ========================================================= public List<decimal> Downtimes { get; set; } }

                                    Is there a way to bind an XRTableCell to an item within an list by index? I've tried binding it using the following in a method of the report but it doesn't work.

                                    newCell.DataBindings.Add("Text", DataSource, "Downtimes.ElementAt(0)");

                                    Any help would be greatly appreciated. If you can suggest another way of storing the data that would allow it to work that would be great too.


                                • J Lewis 01.15.2013

                                  Here's a simple quick project to demonstrate. Imagine that the size of the list in RowObject is determined at runtime from user input (for example, selecting the range of years to report data on where the year would be the column). I hope this helps.

                                2 Solutions

                                Creation Date Importance Sort by

                                Elliot's response was mostly correct but a small change is needed in Detail_BeforePrint to make it work correctly. Here's the code:

                                private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { RowObject dataObject = (RowObject)GetCurrentRow(); List<RowObject> list = (List<RowObject>)this.DataSource; XRTable table = (XRTable)this.Detail.Controls[0]; for (int i = 0; i < table.Rows[0].Cells.Count; i++) { table.Rows[0].Cells[i].Text = dataObject.DataItems[i].ToString(); } }

                                You use GetCurrentRow() to retrieve the current data object for that row and use it populate the table.

                                • Elliot (DevExpress Support) 01.16.2013

                                  Thank you for your reply. I am glad to hear that the issue has been resolved. Please contact us if you experience any further difficulties.

                                Hi ,
                                Please handle the DetailReportBand.BeforePrint event to define text in the table cells. Here ie some sample code:

                                ... public void AddBoundTable(int numberOfDataColumns) { // Create the table XRTable detailTable = new XRTable(); detailTable.LocationF = new PointF(0, 0); detailTable.BeginInit(); // Create the row XRTableRow newRow = new XRTableRow(); newRow.BorderColor = Color.Black; newRow.BorderWidth = 1; newRow.Borders = DevExpress.XtraPrinting.BorderSide.All; newRow.HeightF = 25f; // Create the cells for (int cellCount = 0; cellCount < numberOfDataColumns; cellCount++) { XRTableCell newCell = new XRTableCell(); //string valueName = "DataItems[" + cellCount.ToString() + "]"; //newCell.DataBindings.Add("Text", DataSource, valueName); newRow.Cells.Add(newCell); } detailTable.Rows.Add(newRow); // Size the table to fit the row detailTable.AdjustSize(); detailTable.EndInit(); // Add the table to the ReportHeader band Detail.Controls.Add(detailTable); } private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { List<RowObject> list = (List<RowObject>)this.DataSource; XRTable table = (XRTable)this.Detail.Controls[0]; for (int i = 0; i < table.Rows[0].Cells.Count; i++) { table.Rows[0].Cells[i].Text = list[0].DataItems[i].ToString(); } } ...


                                • J Lewis 01.16.2013

                                  Ah, okay, that works. I thought that event was used for actually printing the report. Thanks for the help.
                                  Just some feedback, Xtrareports is actually really complicated to use for anything beyond creating simple static reports. I know it's a very complicated system but usability could be a lot better.
                                  Thanks again for the great support.

                                • J Lewis 01.16.2013

                                  Okay, I thought it was working but the problem is that the Detail_BeforePrint assumes that the data item in list is the one at index 0. This results in all rows containing the first rows data. I can't find any way in Detail_BeforePrint to determine what data row to populate the values from. Any idea?