private void CreateReport() { // disable all datasources, enable selected only foreach (Base c in Report.Dictionary.AllObjects) { if (c is DataSourceBase && c != DataSource) { (c as DataSourceBase).Enabled = false; } } // create page layout // by default, empty report contains the following bands: ReportTitle, PageHeader, Data, PageFooter ReportPage page = Report.Pages[0] as ReportPage; page.Landscape = rbLandscape.Checked; float pageWidth = (page.PaperWidth - page.LeftMargin - page.RightMargin) * Units.Millimeters; float snapSize = ReportWorkspace.Grid.SnapSize; float defaultHeight = page.IsImperialUnitsUsed ? Units.Inches * 0.2f : Units.Millimeters * 5; // styles if (lbStyles.SelectedIndex != -1) { StyleCollection style = FStyleSheet[FStyleSheet.IndexOf((string)lbStyles.SelectedItem)]; FStyleSheet.Remove(style); FSampleStyleReport.Styles = new StyleCollection(); Report.Styles = style; } // title TextObject title = new TextObject(); title.Parent = page.ReportTitle; title.CreateUniqueName(); title.Dock = DockStyle.Fill; title.HorzAlign = HorzAlign.Center; title.VertAlign = VertAlign.Center; title.Text = DataSource.Alias; title.Style = "Title"; // data and header List <Column> selectedColumns = SelectedColumns; DataBand dataBand = page.Bands[0] as DataBand; dataBand.DataSource = DataSource; if (rbTabular.Checked) { float[] columnWidths = new float[selectedColumns.Count]; float columnWidth = pageWidth / selectedColumns.Count; // try fit to grid columnWidth = (int)(columnWidth / snapSize) * snapSize; for (int i = 0; i < selectedColumns.Count; i++) { columnWidths[i] = columnWidth; } // compensate column widths to fit pagewidth float extraWidth = pageWidth - columnWidth * selectedColumns.Count; for (int i = 0; i < selectedColumns.Count; i++) { if (extraWidth - snapSize < 0) { break; } columnWidths[i] += snapSize; extraWidth -= snapSize; } // create data and header float offsetX = 0; for (int i = 0; i < selectedColumns.Count; i++) { TextObject dataColumn = new TextObject(); dataColumn.Parent = dataBand; dataColumn.CreateUniqueName(); dataColumn.Bounds = new RectangleF(offsetX, 0, columnWidths[i], defaultHeight); dataColumn.Text = "[" + DataSource.Alias + "." + selectedColumns[i].Alias + "]"; dataColumn.Style = "Data"; TextObject headerColumn = new TextObject(); headerColumn.Parent = page.PageHeader; headerColumn.CreateUniqueName(); headerColumn.Bounds = new RectangleF(offsetX, 0, columnWidths[i], defaultHeight); headerColumn.Text = selectedColumns[i].Alias; headerColumn.Style = "Header"; offsetX += columnWidths[i]; } dataBand.Height = defaultHeight; dataBand.EvenStyle = "EvenRows"; page.PageHeader.Height = defaultHeight + snapSize; } else { page.PageHeader = null; // calculate max header width float headerWidth = 0; using (TextObject tempHeader = new TextObject()) { tempHeader.Parent = dataBand; tempHeader.Style = "Header"; for (int i = 0; i < selectedColumns.Count; i++) { tempHeader.Text = selectedColumns[i].Alias; float width = (int)(tempHeader.CalcWidth() / snapSize + 1) * snapSize; if (width > headerWidth) { headerWidth = width; } } } // create data and header float dataWidth = (int)((pageWidth - headerWidth) / snapSize) * snapSize; float offsetY = 0; for (int i = 0; i < selectedColumns.Count; i++) { TextObject headerColumn = new TextObject(); headerColumn.Parent = dataBand; headerColumn.CreateUniqueName(); headerColumn.Bounds = new RectangleF(0, offsetY, headerWidth, defaultHeight); headerColumn.Text = selectedColumns[i].Alias; headerColumn.Style = "Header"; TextObject dataColumn = new TextObject(); dataColumn.Parent = dataBand; dataColumn.CreateUniqueName(); dataColumn.Bounds = new RectangleF(headerWidth, offsetY, dataWidth, defaultHeight); dataColumn.Text = "[" + DataSource.Alias + "." + selectedColumns[i].Alias + "]"; dataColumn.Style = "Data"; offsetY += defaultHeight; } dataBand.Height = offsetY + snapSize; } // groups if (Groups.Count > 0) { // create group headers Base parent = page; foreach (Column column in Groups) { GroupHeaderBand groupHeader = new GroupHeaderBand(); groupHeader.Parent = parent; groupHeader.CreateUniqueName(); groupHeader.Height = defaultHeight; groupHeader.Condition = "[" + DataSource.Alias + "." + column.Alias + "]"; groupHeader.GroupFooter = new GroupFooterBand(); groupHeader.GroupFooter.CreateUniqueName(); groupHeader.GroupFooter.Height = defaultHeight; TextObject groupText = new TextObject(); groupText.Parent = groupHeader; groupText.CreateUniqueName(); groupText.Dock = DockStyle.Fill; groupText.Text = groupHeader.Condition; groupText.Style = "Group"; parent = groupHeader; } // connect last header to the data (parent as GroupHeaderBand).Data = dataBand; } // page footer TextObject pageN = new TextObject(); pageN.Parent = page.PageFooter; pageN.CreateUniqueName(); pageN.Dock = DockStyle.Fill; pageN.HorzAlign = HorzAlign.Right; pageN.Text = "Page [Page]"; pageN.Style = "Footer"; page.PageFooter.Height = defaultHeight; // tell the designer to reflect changes Report.Designer.SetModified(null, "ChangeReport"); }