首页 技术 正文
技术 2022年11月15日
0 收藏 493 点赞 4,998 浏览 2176 个字

原文:DevExpress XtraReports 入门六 控件以程序方式创建一个 交叉表 报表

本文只是为了帮助初次接触或是需要DevExpress XtraReports报表的人群使用的,为了帮助更多的人不会像我这样浪费时间才写的这篇文章,高手不想的看请路过

本文内容来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;
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,112
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,585
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922