您的位置:首页 > 大数据 > 人工智能

DevXpress 控件: 第一篇: 将 Master_Details 关系进行到底--XtraPivotGridControl控件

2008-10-21 09:38 337 查看
一. 控件说明: XtraPivotGridControl;数据控件

二. 控件特点:

1. 支持行, 列字段拖动, 对调

支持行, 列字段的添加, 移除

支持数据字段的添加, 移除, 对调

2. 支持以行, 列字段排序

支持以过滤字段排序

3. 支持行, 列字段过滤

4. 支持行, 列字段的归类, 即形成父子层

横向和竖向同时形成树结构, 可收缩展开

三.测试数据: 1.数据库: sqlserver2000; Norwind

2.关联表: Customers; Orders; Order_Details; Products;

3.DevExpress 版本: V8.1

四. 运行截图:

1. 行字段: 客户名称;订单号

列字段: 产品名称

数据字段: 商品单价;购买数量

过滤字段: 客户公司名称;所签合同名;订购日期;截止日期;提货日期

子逸制作--动态添加字段
/// <summary>
/// 给消费链添加添加字段
/// </summary>
private void AddOrdersColumns()
{
//Customers表
PivotGridField customerID = new PivotGridField();
customerID.FieldName = "CustomerID";
customerID.Caption = "客户名称";
customerID.Area = DevExpress.XtraPivotGrid.PivotArea.RowArea;

PivotGridField companyName = new PivotGridField();
companyName.FieldName = "CompanyName";
companyName.Caption = "客户公司名称";
companyName.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;
companyName.Width = 150;

PivotGridField contactTitle = new PivotGridField();
contactTitle.FieldName = "ContactTitle";
contactTitle.Caption = "所签合同名";
contactTitle.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;

//Orders表
PivotGridField orderID = new PivotGridField();
orderID.FieldName = "OrderID";
orderID.Caption = "订单号";
orderID.Area = DevExpress.XtraPivotGrid.PivotArea.RowArea;

PivotGridField orderDate = new PivotGridField();
orderDate.FieldName = "OrderDate";
orderDate.Caption = "订购日期";
orderDate.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;

PivotGridField requiredDate = new PivotGridField();
requiredDate.FieldName = "RequiredDate";
requiredDate.Caption = "截止日期";
requiredDate.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;

PivotGridField shippedDate = new PivotGridField();
shippedDate.FieldName = "ShippedDate";
shippedDate.Caption = "提货日期";
shippedDate.Area = DevExpress.XtraPivotGrid.PivotArea.FilterArea;

//OrderDetails
PivotGridField unitPrice = new PivotGridField();
unitPrice.FieldName = "UnitPrice";
unitPrice.Caption = "商品单价";
unitPrice.Area = DevExpress.XtraPivotGrid.PivotArea.DataArea;

PivotGridField Quantity = new PivotGridField();
Quantity.FieldName = "Quantity";
Quantity.Caption = "购买数量";
Quantity.Area = DevExpress.XtraPivotGrid.PivotArea.DataArea;

//Product表
PivotGridField productName = new PivotGridField();
productName.FieldName = "ProductName";
productName.Caption = "产品名称";
productName.Area = DevExpress.XtraPivotGrid.PivotArea.ColumnArea;

//添加到控制中
this.pivotGridControl1.Fields.Add(customerID);
this.pivotGridControl1.Fields.Add(companyName);
this.pivotGridControl1.Fields.Add(contactTitle);

this.pivotGridControl1.Fields.Add(orderID);

this.pivotGridControl1.Fields.Add(orderDate);
this.pivotGridControl1.Fields.Add(requiredDate);
this.pivotGridControl1.Fields.Add(shippedDate);

this.pivotGridControl1.Fields.Add(unitPrice);
this.pivotGridControl1.Fields.Add(Quantity);

this.pivotGridControl1.Fields.Add(productName);

}



2. 运行时改变字段的显示区域

customerID.Area = DevExpress.XtraPivotGrid.PivotArea.RowArea;

五. 属性

1. 允许拖动

this.pivotGridControl1.OptionsCustomization.AllowDrag = true;

2. 允许排序

this.pivotGridControl1.OptionsCustomization.AllowSort = true;

3. 允许过滤

this.pivotGridControl1.OptionsCustomization.AllowFilter = true;

六: 总结后记

1. 此控件较为灵活;对于 Master_Details 关系表处理的相当好;

2. 此控件数据区只能显示数字类型字段, 类似于统计分析;

3. 后面会有更多的 DevExpress 控件介绍给大家

4. 这里只介绍控件的简单使用;如需更复杂的技术支持或交流请与作者联系;

QQ: 915571300 子逸

5. 版权所有: 子逸(博客园);转载请注明出处;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐