안녕하세요 그레이프시티입니다.
별도로 이것을 위해 기능이 제공되는 것은 없습니다
그래서 열의 데이터에 따라 사용자 정의하여 구현해야 합니다.
고정된 행을 제외하고 Flexgrid를 정렬하려면 아래와 같이 SortingColumn 이벤트와 Icomparer 인터페이스를 사용시면 됩니다.
예를 들어 첫 번째 열에 대한 정렬을 구현하려면 다음과 같습니다.
1) SortingColumn Event
private void Grid_SortingColumn(object sender, C1.WPF.FlexGrid.CellRangeEventArgs e)
{
e.Cancel = true;
SmartSort(sender, e.Column);
}
private void SmartSort(object sender, int column)
{
if(direction==ListSortDirection.Ascending) { direction = ListSortDirection.Descending; }
else { direction = ListSortDirection.Ascending;}
var dg = sender as C1.WPF.FlexGrid.C1FlexGrid;
var lcv = (ListCollectionView)CollectionViewSource.GetDefaultView(dg.ItemsSource);
lcv.CustomSort = new SmartSorter(direction,grid.FrozenRows);
}
2) IComparer Interface
public class SmartSorter : IComparer
{
public ListSortDirection Direction { get; private set; }
public int FrozenRow { get; set; }
public SmartSorter(ListSortDirection direction,int rw)
{
Direction = direction;
FrozenRow = rw;
}
public int Compare(object x, object y)
{
var dummyx = x as Student;
var dummyy = y as Student;
int valorx = dummyx.Sno;
int valory = dummyy.Sno;
if (valorx < FrozenRow && valory < FrozenRow)
return 0;
if (valorx <FrozenRow)
return -1;
if (valory <FrozenRow)
return 1;
if (Direction == ListSortDirection.Ascending)
{
return valory.CompareTo(valorx);
}
else
{
return valorx.CompareTo(valory);
}
}
}
간단한 샘플 프로젝트를 첨부드리니 참고해 주시기 바랍니다.
추가 문의가 있으시면 언제든 알려 주시기 바랍니다.
감사합니다.
그레이프시티 드림