Article information
Article relates to
Q3 2012 SP1
Created by
Stefan Stefanov
Last modified
25 Dec 2012
Last modified by
This example shows how to use both the default and custom sorting to sort your grid. In the below grid all columns prior Column2 are sorted with the default sort mechanism, while for Column2 itself, we will use custom sorting.
void
radGridView1_CustomSorting(
object
sender, Telerik.WinControls.UI.GridViewCustomSortingEventArgs e)
{
//sort all descriptors before 'column2' are using the default comparer
SortDescriptorCollection descriptors = e.Template.SortDescriptors;
int
index = descriptors.IndexOf(
"Column2"
);
if
(index > 0)
SortDescriptorCollection context =
new
SortDescriptorCollection();
for
(
i = 0; i < index; i++)
context.Add(descriptors[i]);
}
e.SortResult = GridViewRowInfoComparer.CompareRows(e.Row1, e.Row2, context);
(e.SortResult == 0 && index >= 0)
decimal
value1 = (
)e.Row1.Cells[
].Value;
value2 = (
)e.Row2.Cells[
e.SortResult =
.Compare(value1, value2);
(e.SortResult != 0)
(descriptors[index].Direction == System.ComponentModel.ListSortDirection.Descending)
e.SortResult *= -1;
return
;
//default sorting
e.Handled =
false
Private
Sub
radGridView1_CustomSorting(sender
As
Object
, e
Telerik.WinControls.UI.GridViewCustomSortingEventArgs)
'sort all descriptors before 'column2' are using the default comparer
Dim
descriptors
SortDescriptorCollection = e.Template.SortDescriptors
index
Integer
= descriptors.IndexOf(
)
If
index > 0
Then
context
New
SortDescriptorCollection()
For
i
= 0
To
index - 1
context.Add(descriptors(i))
Next
e.SortResult = GridViewRowInfoComparer.CompareRows(e.Row1, e.Row2, context)
End
e.SortResult = 0
AndAlso
index >= 0
value1
Decimal
=
CDec
(e.Row1.Cells(
).Value)
value2
(e.Row2.Cells(
.Compare(value1, value2)
e.SortResult <> 0
descriptors(index).Direction = System.ComponentModel.ListSortDirection.Descending
e.SortResult *= -1
Return
'default sorting
False
Resources Buy Try