原創(chuàng)|其它|編輯:郝浩|2012-11-05 13:14:00.000|閱讀 442 次
概述:DevExpress XtraPivotGrid對過濾器下拉項(xiàng)進(jìn)行排序。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
本示例演示了如何排序在一個(gè)過濾器下拉項(xiàng)進(jìn)行自定義排序。
本示例中的CustomFilterPopupItems事件是用來管理篩選項(xiàng)目列表的。當(dāng)最終用戶調(diào)用過濾器下拉,就會(huì)引發(fā)這個(gè)事件。CustomFilterPopupItems事件參數(shù)提供訪問過濾器的項(xiàng)目清單,如果相應(yīng)的選項(xiàng)被選中,就會(huì)根據(jù)項(xiàng)目標(biāo)題的長度對過濾器下拉項(xiàng)進(jìn)行排序。
示例代碼如下:
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
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)