DevExpress XtraReports 入门六 控件以程序方式创建一个 交叉表 报表
2014-05-05 14:11
633 查看
原文:DevExpress XtraReports 入门六 控件以程序方式创建一个 交叉表 报表本文只是为了帮助初次接触或是需要DevExpress XtraReports报表的人群使用的,为了帮助更多的人不会像我这样浪费时间才写的这篇文章,高手不想的看请路过
本文内容来DevExpress XtraReports帮助文档,如看过类似的请略过。
废话少说 开始正事
在继续本示例之前,要把所有 必需的程序集 添加到项目的 引用 列表中,并且把一个按钮拖放到窗体上。 然后,以下列方式接管此按钮的 Click 事件。
本文内容来DevExpress XtraReports帮助文档,如看过类似的请略过。
废话少说 开始正事
在继续本示例之前,要把所有 必需的程序集 添加到项目的 引用 列表中,并且把一个按钮拖放到窗体上。 然后,以下列方式接管此按钮的 Click 事件。
using System; using System.Data; using System.Data.OleDb; using System.Windows.Forms; using DevExpress.XtraPivotGrid; using DevExpress.XtraReports.UI; using DevExpress.XtraReports.UI.PivotGrid; // ... namespace docXRPivotGrid { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { // Create a cross-tab report. XtraReport report = CreateReport(); // Show its Print Preview. report.ShowPreview(); } private XtraReport CreateReport() { // Create a blank report. XtraReport rep = new XtraReport(); // Create a detail band and add it to the report. DetailBand detail = new DetailBand(); rep.Bands.Add(detail); // Create a pivot grid and add it to the Detail band. XRPivotGrid pivotGrid = new XRPivotGrid(); detail.Controls.Add(pivotGrid); // Create a data connection. OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\nwind.mdb"); // Create a data adapter. OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT CategoryName, ProductName, Country, [Sales Person], Quantity, [Extended Price] FROM SalesPerson", connection); // Creata a dataset and fill it. DataSet dataSet1 = new DataSet(); adapter.Fill(dataSet1, "SalesPerson"); // Bind the pivot grid to data. pivotGrid.DataSource = dataSet1; pivotGrid.DataMember = "SalesPerson"; // Generate pivot grid's fields. XRPivotGridField fieldCategoryName = new XRPivotGridField("CategoryName", PivotArea.RowArea); XRPivotGridField fieldProductName = new XRPivotGridField("ProductName", PivotArea.RowArea); XRPivotGridField fieldCountry = new XRPivotGridField("Country", PivotArea.ColumnArea); XRPivotGridField fieldSalesPerson = new XRPivotGridField("Sales Person", PivotArea.ColumnArea); XRPivotGridField fieldQuantity = new XRPivotGridField("Quantity", PivotArea.DataArea); XRPivotGridField fieldExtendedPrice = new XRPivotGridField("Extended Price", PivotArea.DataArea); // Add these fields to the pivot grid. pivotGrid.Fields.AddRange(new PivotGridField[] {fieldCategoryName, fieldProductName, fieldCountry, fieldSalesPerson, fieldQuantity, fieldExtendedPrice}); return rep; } } }
相关文章推荐
- DevExpress XtraReports 入门六 控件以程序方式创建一个 交叉表 报表
- DevExpress XtraReports报表入门教程:创建一个Master-Detail主从报表
- [原创]Devexpress XtraReports 系列 5 创建交叉报表
- DevExpress XtraReports 入门一 创建 Hello World 报表
- DevExpress XtraReports 入门一 创建 Hello World 报表
- DevExpress XtraReports 入门二 创建 data-aware(数据感知) 报表
- DevExpress XtraReports 入门三 创建 Master-Detail(主/从) 报表
- DevExpress XtraReports 入门四 创建 Web 报表
- DevExpress XtraReports控件创建主从报表的两种方法
- DevExpress XtraReports 入门五 创建交叉表报表
- iPhone开发入门3 - 创建一个UITable View程序
- (转)Inno Setup入门(四)——为程序创建桌面快捷方式
- 该程序在运行时会创建一个JOB,并且将该自己以JOB后台方式运行,并且可以从前台传递参数到后台JOB
- iPhone开发入门4 - 创建一个UITable View程序,不使用Interface Builder
- [原创]Devexpress XtraReports 系列 1 创建静态报表
- 手把手做一个JSP入门程序(二):创建一个项目(JSP)
- 在DevExpress程序中使用条形码二维码控件,以及进行报表打印处理
- [原创]Devexpress XtraReports 系列 10 创建标签报表
- WCF入门---创建一个简单的WCF程序
- [DevExpress]程序中使用条形码二维码控件,以及进行报表打印处理