using DevExpress.CodeParser; using DevExpress.XtraReports.UI; using System; using System.Collections; using System.ComponentModel; using System.Drawing; namespace HStation.ReportFile.SDK { public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport { public XtraReport1() { InitializeComponent(); ininal(); } private void ininal() { // 获取数据源 List dataSource = CreateSampleProductList(); this.DataSource = dataSource; // this.xrTable1.DataBindings.Add("Text", dataSource, "Price"); // this.DataSource = dataSource; this.xrTable2.DataBindings.Add("Text", dataSource, "Price"); this.xrTable2.DataBindings.Add("Text", dataSource, "ProductName"); // 设置报表的数据源 // this.DataSource = dataSource; /* // 创建表头 XRTableRow headerRow = new XRTableRow(); headerRow.Cells.Add(new XRTableCell { Text = "ProductName" }); headerRow.Cells.Add(new XRTableCell { Text = "Price" }); xrTable1.Rows.Add(headerRow);*/ /* // 自动创建数据行和单元格并绑定数据 foreach (var item in dataSource) { XRTableRow dataRow = new XRTableRow(); XRTableCell productNameCell = new XRTableCell(); productNameCell.DataBindings.Add("Text", dataSource, "ProductName"); dataRow.Cells.Add(productNameCell); XRTableCell priceCell = new XRTableCell(); priceCell.DataBindings.Add("Text", dataSource, "Price"); dataRow.Cells.Add(priceCell); xrTable1.Rows.Add(dataRow); }*/ } public class Product { public string ProductName { get; set; } public decimal Price { get; set; } } public List CreateSampleProductList() { List products = new List { new Product { ProductName = "苹果", Price = 5.99m }, new Product { ProductName = "香蕉", Price = 3.99m }, new Product { ProductName = "橙子", Price = 4.99m } }; return products; } } }