첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ XAML

<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>

 

728x90

 

▶ C#

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

 

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요