This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.xaml.cs
69 lines (64 loc) · 2.65 KB
/
MainWindow.xaml.cs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.PivotGrid;
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
namespace Wpf_PivotGrid_CustomFieldSort_Example
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public ObservableCollection<MyOrderRow> OrderSourceList {get; set;}
public MainWindow()
{
InitializeComponent();
pivotGridControl1.CustomFieldSort += PivotGridControl1_CustomFieldSort;
checkEdit1.Checked += CheckEdit1_Checked;
checkEdit1.Unchecked += CheckEdit1_Unchecked;
}
private void CheckEdit1_Unchecked(object sender, RoutedEventArgs e)
{
// Set the default sorting algorithm.
fieldSalesPerson.SortMode = FieldSortMode.Default;
}
private void CheckEdit1_Checked(object sender, RoutedEventArgs e)
{
// Enable the CustomFieldSort event for the fieldSalesPerson field.
fieldSalesPerson.SortMode = FieldSortMode.Custom;
}
private void PivotGridControl1_CustomFieldSort(object sender, DevExpress.Xpf.PivotGrid.PivotCustomFieldSortEventArgs e)
{
if (e.Field.FieldName == "SalesPersonName")
{
int result;
if (e.SortLocation == FieldSortLocation.Pivot)
{
object orderValue1 = e.GetListSourceColumnValue(e.ListSourceRowIndex1, "SalesPersonId"),
orderValue2 = e.GetListSourceColumnValue(e.ListSourceRowIndex2, "SalesPersonId");
result = Comparer.Default.Compare(orderValue1, orderValue2);
}
else
{
// Compare last names.
result = Comparer.Default.Compare(e.Value1.ToString().Split(' ')[1], e.Value2.ToString().Split(' ')[1]);
// If last names are the same, compare first names.
if (result == 0)
result = Comparer.Default.Compare(e.Value1.ToString().Split(' ')[0], e.Value2.ToString().Split(' ')[0]);
}
e.Result = result;
e.Handled = true;
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
OrderSourceList = DatabaseHelper.CreateData();
pivotGridControl1.DataSource = OrderSourceList;
pivotGridControl1.BestFitArea = DevExpress.Xpf.PivotGrid.FieldBestFitArea.FieldHeader;
pivotGridControl1.BestFit();
}
}
}