XtraReports WinForms入门教程五:以程序方式创建一个 交叉表报表
作者:zhuhm 来源:本站原创 浏览:Loading...次 发布时间:2012-10-12 评论:0条
在上一篇文章 XtraReports WinForms入门教程四:创建交叉报表 中,我们主要介绍了如何在设计时使用Detail Report Bands创建一个交叉报表。而本文则主要介绍以程序方式创建一个 交叉表报表。
在继续本示例之前,要把所有 必需的程序集 添加到项目的 引用 列表中,并且把一个按钮拖放到窗体上。 然后,以下列方式接管此按钮的 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控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/Resources/Documentation-280.html
关键字: 报表 WinForms报表 .NET报表
评论列表
暂无评论
请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!
慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。
电话:400-700-1020
023-66090381
邮箱:sales@evget.com