This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
Form1.vb
48 lines (45 loc) · 1.75 KB
/
Form1.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Imports System
Imports System.Collections
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid
Imports DevExpress.XtraPivotGrid.Data
Namespace XtraPivotGrid_SortedFilterItems
Partial Public Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Public Sub New()
InitializeComponent()
excelDataSource1.FileName = "SalesPerson.xlsx"
excelDataSource1.Fill()
AddHandler pivotGridControl1.CustomFilterPopupItems, AddressOf pivotGridControl1_CustomFilterPopupItems
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
pivotGridControl1.DataSource = excelDataSource1
pivotGridControl1.BestFit()
End Sub
Private Sub pivotGridControl1_CustomFilterPopupItems(ByVal sender As Object, ByVal e As PivotCustomFilterPopupItemsEventArgs)
If rbCaptionLength.Checked Then
ArrayList.Adapter(DirectCast(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
fieldProductName1.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 = DirectCast(x, PivotGridFilterItem)
Dim item2 As PivotGridFilterItem = DirectCast(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