XtraPivotControl使用指南

更新时间:2024-06-03 18:37:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

XtraPivotControl使用指南

一、数据源绑定

二、类

网格:XtraPivotControl

区域:PivotArea(FilterArea,columnArea,RowArea,DataArea) 字段:PivotGridField 字段组:PivotGridGroup 三、属性

XtraPivotControl:

.DataSource:DataSet,DataView,DataTable .DataMember:DataTable

.Fields:包含的所有的字段属性 Add(field) Add(field,area) AddRange(fields[]) .Groups: 包含的属性组

.Add()

.AddRange(Groups)

.FormatConditions.AddRange 条件格式化

.AddRange(PivotGridStyleFormatConditions) 增加格式化条件(示例:八)

.Name:网格名称

.OptionsView 控制隐藏或显示界面上的一些元素(Grand Total, Total, Header etc.)

.ShowColumnGrandTotals .ShowColumnTotals

.OptionsHint 对于提示文件的相关控制属性

.ShowCellHints 隐藏或显示提示文字 .OptionsSelection

.CellSelection 控制是否以可以单击行、列标题来选中网格数据 .MultiSelection

.OptionsMenu 控制各个区域是否弹出菜单(默认弹出菜单)

. EnableFieldValueMenu, .EnableHeaderAreaMenu .EnableHeaderMenu PivotGridField: Name:名称

FieldName:属性名 Caption:标题

UnboundFieldName:不绑定数据源属性(重新计算属性,默认为对象名) UnboundType:属性类型(枚举型)

GroupInterval: 时间日期分组(枚举型),如果选中,属性为不绑定属性(重新计算属性) CellFormat.FormatType:单元格格式化类型(枚举型) CellFormat.FormatString:单元格格式化字符串 ValueFormat.FormatType: ValueFormat.FormatString

SummaryDisplayType: SummaryType:统计类型

ShowSummaryTypeName:是否显示统计类型名(true,false)

AllowedAreas:枚举型(All,DataArea……),属性允许停靠的区域

FilterVAlues:过滤值 FilterType:过滤类型

.Options 控制隐藏或显示界面上的一些元素(Grand Total, Total, Header etc.)

.AllowDrag .AllowExpand .AllowFilter

.SortBySummaryInfo 汇总排序

.Field

.FieldName

***PivotGridGroup属性组 Fields

Add(field)

AddRange(fields) 四:方法

XtraPivotControl:

.SavePivotGridToFile(filePath):保存当前网格到指定文件(file.dat) .SaveLayoutToXML(保存网格当前布局至XML文件) .RestoreLayoutFormXML:从XML文件读取网格布局 .ExportToXls(filePath):导出文件至Excel文件

.RefreshData() 刷新数据源,当数据源有更新时,可以使用此方法刷新控件

.CalcHitInfo(new Point(e.X, e.Y)));获取单元格的详细信息

使用示例:

DevExpress.XtraPivotGrid.PivotGridHitInfo info = pivotGridControl1.CalcHitInfo(); MessageBox.Show(\ + info.CellInfo.DisplayText + \ + \+info.CellInfo.Value + \ +

\ + info.CellInfo.RowIndex + \ + \ + info.CellInfo.ColumnIndex + \ +

\ + info.CellInfo.DataField.ToString());

五:事件

XtraPivotControl:

CustomUnboundFieldData:自定义属性发生事件

示例:

private void pivotGridControl1_CustomUnboundFieldData(object sender, DevExpress.XtraPivotGrid.CustomFieldDataEventArgs e){ if (e.Field.Name == \ decimal totalPrice =

Convert.ToDecimal(e.GetListSourceColumnValue(\ e.Value = totalPrice * Convert.ToDecimal(0.5); }}

FieldValueDisplayText:自定义属性显示文本发生事件 CustomSummary:自定义统计函数发生事件 FocusedCellChanged:获得焦点单元格触发事件 CellSelectionChanged:选中单元格触发事件 六:特殊功能 事件参数类

PivotCellEventArgs

方法:CreateDrillDownDataSource 描述:根据客户事件创建数据源 PivotCellBaseEventArgs

方法:CreateDrillDownDataSource 描述:根据客户事件创建数据源

PivotGridControl本身就可以当作其它数据控件的数据源来使用,因为它实现了IBindingList接口,当它作为其它控件的数据源时,它会将当前被选中的单元格数据生成一张二维表格,其字段为: Series 包含单元格的列标题(多层标题之间用竖线分开,例:大类|中类|小类) Arguments 包含单元格的行标题(多层标题之间用竖线分开) Values 包含单元格的值

PivotDrillDownDataSource:

描述:获取获取焦点的单元格属性与数据,创建新的数据源 示例:

DevExpress.XtraPivotGrid.PivotDrillDownDataSource ds =

pivotGridControl1.Cells.GetFocusedCellInfo().CreateDrillDownDataSource();

String str = \;

foreach (DevExpress.XtraPivotGrid.PivotDrillDownDataRow row in ds) {

str += row[\].ToString(); str += \; //do something }

MessageBox.Show(str);

七:统计函数

所有的统计函数都可以用于数字类型,非数字类型仅仅能用:Max,Min,Count Count: 计数 Sum:求和 Max;最大值 Min:最小值 Average:平均值

StdDev:标准差估计

StdDevp:标准偏差

Var :

Varp :

Custom:自定义,必须实现CustomSummary事件

八:条件格式化

PivotGridStyleFormatCondition: 属性:

.Appearance.BackColor = System.Drawing.Color.Yellow; .Appearance.Options.UseBackColor = true; .ApplyToCustomTotalCell = false; .ApplyToGrandTotalCell = false; .ApplyToTotalCell = false;

.Condition = DevExpress.XtraGrid.FormatConditionEnum.Less; .Field = this.fieldExtendedPrice; .FieldName = \;

.Value1 = new decimal(new int[] {10000,0,0,0});

PivotGridControl:

this.pivotGridControl1.FormatConditions.AddRange(new DevExpress.XtraPivotGrid.PivotGridStyleFormatCondition[] {pivotGridStyleFormatCondition1,…… });

本文来源:https://www.bwwdw.com/article/0g46.html

Top