彩票走势图

DevExpress XtraPivotGrid对过滤器下拉项进行排序

原创|其它|编辑:郝浩|2012-11-05 13:14:00.000|阅读 424 次

概述:DevExpress XtraPivotGrid对过滤器下拉项进行排序。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>


本示例演示了如何排序在一个过滤器下拉项进行自定义排序。

本示例中的CustomFilterPopupItems事件是用来管理筛选项目列表的。当最终用户调用过滤器下拉,就会引发这个事件。CustomFilterPopupItems事件参数提供访问过滤器的项目清单,如果相应的选项被选中,就会根据项目标题的长度对过滤器下拉项进行排序。

示例代码如下:

C#

using System;
using System.Collections;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;
using DevExpress.XtraPivotGrid.Data;

namespace XtraPivotGrid_ExampleTemplate {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) {
            DataSet1TableAdapters.ProductReportsTableAdapter tableAdapter =
                new DataSet1TableAdapters.ProductReportsTableAdapter();
            pivotGridControl1.DataSource = tableAdapter.GetData();
            pivotGridControl1.BestFit();
        }
        private void pivotGridControl1_CustomFilterPopupItems(object sender, 
            PivotCustomFilterPopupItemsEventArgs e) {
            if(rbCaptionLength.Checked)
                ArrayList.Adapter((IList)e.Items).Sort(new FilterItemsComparer());
        }
        private void rbAlphabeticalSort_CheckedChanged(object sender, EventArgs e) {
            fieldProductName.ShowFilterPopup();
        }
    }
    public class FilterItemsComparer : IComparer {
        int IComparer.Compare(object x, object y) {
            if (!(x is PivotGridFilterItem) || !(y is PivotGridFilterItem)) return 0;
            PivotGridFilterItem item1 = (PivotGridFilterItem)x;
            PivotGridFilterItem item2 = (PivotGridFilterItem)y;
            if (item1.ToString().Length == item2.ToString().Length) return 0;
            if (item1.ToString().Length > item2.ToString().Length) return 1;
            return -1;
        }
    }
}

VB

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid
Imports DevExpress.XtraPivotGrid.Data

Namespace XtraPivotGrid_ExampleTemplate
    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
            Dim tableAdapter As New DataSet1TableAdapters.ProductReportsTableAdapter()
            pivotGridControl1.DataSource = tableAdapter.GetData()
            pivotGridControl1.BestFit()
        End Sub
        Private Sub pivotGridControl1_CustomFilterPopupItems(ByVal sender As Object, _
                ByVal e As PivotCustomFilterPopupItemsEventArgs) _
                Handles pivotGridControl1.CustomFilterPopupItems
            If rbCaptionLength.Checked Then
                ArrayList.Adapter(CType(e.Items, IList)).Sort(New FilterItemsComparer())
            End If
        End Sub
        Private Sub rbAlphabeticalSort_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) _
                Handles rbAlphabeticalSort.CheckedChanged
            fieldProductName.ShowFilterPopup()
        End Sub
    End Class
    Public Class FilterItemsComparer
        Implements IComparer
        Private Function IComparer_Compare(ByVal x As Object, ByVal y As Object) As Integer _
                Implements IComparer.Compare
            If Not(TypeOf x Is PivotGridFilterItem) OrElse Not(TypeOf y Is PivotGridFilterItem) Then
                Return 0
            End If
            Dim item1 As PivotGridFilterItem = CType(x, PivotGridFilterItem)
            Dim item2 As PivotGridFilterItem = CType(y, PivotGridFilterItem)
            If item1.ToString().Length = item2.ToString().Length Then
                Return 0
            End If
            If item1.ToString().Length > item2.ToString().Length Then
                Return 1
            End If
            Return -1
        End Function
    End Class
End Namespace

慧都学院2017全新DevExpress线下研修班火热报名中!



标签:DevExpress

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn

文章转载自:慧都控件网

为你推荐

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


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP