■ GridControl 클래스의 CustomColumnSort 이벤트를 사용하여 커스텀 컬럼을 정렬하는 방법을 보여준다.
▶ 예제 코드 (XAML)
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 |
<Window x:Class="HowToImplementCustomSorting.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" Width="600" Height="450" Title="Implement Custom Sorting" Loaded="Window_Loaded"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <CheckBox Grid.Row="0" Margin="10" FontFamily="바탕체" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Custom Sort" Checked="_pCheckBox_Checked" Unchecked="_pCheckBox_Unchecked" /> <dxg:GridControl x:Name="gridControl" Grid.Row="1" CustomColumnSort="gridControl_CustomColumnSort"> <dxg:GridControl.View> <dxg:TableView x:Name="tableView" ShowGroupPanel="False" NavigationStyle="None" /> </dxg:GridControl.View> </dxg:GridControl> </Grid> </Window> |
▶ 예제 코드 (C#)
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
using System.Windows; using System.Collections.Generic; using DevExpress.Xpf.Grid; using DevExpress.XtraGrid; #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e) /// <summary> /// 윈도우 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Window_Loaded(object sender, RoutedEventArgs e) { string[] monthArray = new string[] { "January", "February", "March" , "April" , "May" , "June" , "July" , "August" , "September", "October", "November", "December" }; this.gridControl.ItemsSource = monthArray; this.gridControl.PopulateColumns(); this.gridControl.SortBy(this.gridControl.Columns[0]); } #endregion #region 체크 박스 체크시 처리하기 - checkBox_Checked(sender, e) /// <summary> /// 체크 박스 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkBox_Checked(object sender, RoutedEventArgs e) { this.gridControl.Columns[0].SortMode = ColumnSortMode.Custom; this.gridControl.SortBy(this.gridControl.Columns[0]); } #endregion #region 체크 박스 체크시 처리하기 - checkBox_Checked(sender, e) /// <summary> /// 체크 박스 체크시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void checkBox_Unchecked(object pSender, RoutedEventArgs e) { this.gridControl.Columns[0].SortMode = ColumnSortMode.Default; this.gridControl.SortBy(this.gridControl.Columns[0]); } #endregion #region 그리드 컨트롤 커스텀 컬럼 정렬시 처리하기 - gridControl_CustomColumnSort(sender, e) /// <summary> /// 그리드 컨트롤 커스텀 컬럼 정렬시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gridControl_CustomColumnSort(object sender, CustomColumnSortEventArgs e) { e.Result = Comparer<int>.Default.Compare ( e.ListSourceRowIndex1, e.ListSourceRowIndex2 ); e.Handled = true; } #endregion |