彩票走势图

示例演示如何使用DevExpress XtraPivotGrid自定义组过滤器

原创|其它|编辑:郝浩|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@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP