Support
Joined: 18 Jul 2005 Posts: 731
|
Posted: Sat Oct 20, 2007 3:10 am Post subject: HOWTO: Implement custom sorting of items |
|
|
Items can be sorted using programmer-defined custom logic. To use custom sorting, use the BeforeColumnSort and CompareItems events as follows :
[C#]
private void fileView1_BeforeColumnSort(object sender, LogicNP.FileViewControl.ColumnSortEventArgs e)
{
// Specify custom sorting
e.SortMethod=LogicNP.FileViewControl.SortMethods.CustomSorting;
}
private void fileView1_CompareItems(object sender, LogicNP.FileViewControl.CompareItemsEventArgs e)
{
// Set e.Comparison to indicate sort order; e.Item1 and e.Item2 specify the items being compared
// This example sorts items by the length of their displayname.
e.Comparison = e.Item1.DisplayName.Length - e.Item2.DisplayName.Length;
}
[VB.Net]
Private Sub FileView1_BeforeColumnSort(ByVal sender As Object, ByVal e As LogicNP.FileViewControl.ColumnSortEventArgs) Handles FileView1.BeforeColumnSort
' Specify custom sorting
e.SortMethod = LogicNP.FileViewControl.SortMethods.CustomSorting
End Sub
Private Sub FileView1_CompareItems(ByVal sender As Object, ByVal e As LogicNP.FileViewControl.CompareItemsEventArgs) Handles FileView1.CompareItems
' Set e.Comparison to indicate sort order; e.Item1 and e.Item2 specify the items being compared
' This example sorts items by the length of their displayname.
e.Comparison = e.Item1.DisplayName.Length - e.Item2.DisplayName.Length
End Sub |
|