原創|其它|編輯:郝浩|2012-10-31 10:11:04.000|閱讀 677 次
概述:本文通過一個具體的示例,演示了DevExpress XtraPivotGrid 如何使用自定義組過濾器過濾數據。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
本文通過一個具體的示例,演示了DevExpress XtraPivotGrid 如何使用自定義組過濾器過濾數據。
在本示例中,有四個預置組過濾器條件可以應用于PivotGrid。示例中,使用單選按鈕來實現它們之間切換。
事例代碼如下:
C#
using System; using System.Windows.Forms; using DevExpress.XtraPivotGrid; namespace HierarchicalFilters { public partial class Form1 : Form { public Form1() { InitializeComponent(); } void Form1_Load(object sender, EventArgs e) { this.pivotGridControl1.DataSource = GetTimeTableView(); fieldMonth.CollapseAll(); } void radioGroup1_SelectedIndexChanged(object sender, EventArgs e) { if (pivotGridControl1 == null) return; this.pivotGridControl1.BeginUpdate(); PivotGridGroup group = this.pivotGridControl1.Groups[0]; group.FilterValues.Reset(); group.FilterValues.BeginUpdate(); switch (radioGroup1.SelectedIndex) { case 0: group.FilterValues.FilterType = PivotFilterType.Excluded; break; case 1: group.FilterValues.FilterType = PivotFilterType.Included; group.FilterValues.Values.Add(2009).ChildValues.Add(12); group.FilterValues.Values.Add(2010).ChildValues.Add(1); break; case 2: group.FilterValues.FilterType = PivotFilterType.Excluded; group.FilterValues.Values.Add(2009); break; case 3: group.FilterValues.FilterType = PivotFilterType.Included; SelectFirstDays(group); break; } group.FilterValues.EndUpdate(); this.pivotGridControl1.EndUpdate(); if (radioGroup1.SelectedIndex == 3) fieldMonth.ExpandAll(); else fieldMonth.CollapseAll(); } void SelectFirstDays(PivotGridGroup group) { foreach(object year in group.GetUniqueValues(null)) { PivotGroupFilterValue value = group.FilterValues.Values.Add(year); foreach(object month in group.GetUniqueValues(new object[] { year })) { value.ChildValues.Add(month).ChildValues.Add(1); } } } } }
VB
Imports Microsoft.VisualBasic Imports System Imports System.Windows.Forms Imports DevExpress.XtraPivotGrid Namespace HierarchicalFilters Partial Public Class Form1 Inherits Form Public Sub New() InitializeComponent() End Sub Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load Me.pivotGridControl1.DataSource = GetTimeTableView() fieldMonth.CollapseAll() End Sub Private Sub radioGroup1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) _ Handles radioGroup1.SelectedIndexChanged If pivotGridControl1 Is Nothing Then Return End If Me.pivotGridControl1.BeginUpdate() Dim group As PivotGridGroup = Me.pivotGridControl1.Groups(0) group.FilterValues.Reset() group.FilterValues.BeginUpdate() Select Case radioGroup1.SelectedIndex Case 0 group.FilterValues.FilterType = PivotFilterType.Excluded Case 1 group.FilterValues.FilterType = PivotFilterType.Included group.FilterValues.Values.Add(2009).ChildValues.Add(12) group.FilterValues.Values.Add(2010).ChildValues.Add(1) Case 2 group.FilterValues.FilterType = PivotFilterType.Excluded group.FilterValues.Values.Add(2009) Case 3 group.FilterValues.FilterType = PivotFilterType.Included SelectFirstDays(group) End Select group.FilterValues.EndUpdate() Me.pivotGridControl1.EndUpdate() If radioGroup1.SelectedIndex = 3 Then fieldMonth.ExpandAll() Else fieldMonth.CollapseAll() End If End Sub Private Sub SelectFirstDays(ByVal group As PivotGridGroup) For Each year As Object In group.GetUniqueValues(Nothing) Dim value As PivotGroupFilterValue = group.FilterValues.Values.Add(year) For Each month As Object In group.GetUniqueValues(New Object() { year }) value.ChildValues.Add(month).ChildValues.Add(1) Next month Next year End Sub End Class End Namespace
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網