This is a migrated thread and some comments may be shown as answers.

How do you determine what column fire custom sort event?

3 Answers 37 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 21 Jul 2011, 02:54 PM
What I am looking for in how to determine what column the grid is being sorted on when the CustomSort event is being fired. I see there is a property column that appears to provide this information but it is marked obsolete so therefore will not compile. Could someone point me in the right direction?

3 Answers, 1 is accepted

Sort by
0
Accepted
AaronP
Top achievements
Rank 1
answered on 21 Jul 2011, 04:45 PM
Hi David,

I'm using the 2011 Q1 SP1 release, so for the release you are using it might be different.  I use this:

gridView.SortDescriptors[0].PropertyName 

Help that helps,

Aaron
0
David
Top achievements
Rank 1
answered on 21 Jul 2011, 05:21 PM
Thanks much. That does exactly what I was looking for.
0
Julian Benkov
Telerik team
answered on 26 Jul 2011, 03:12 PM
Hello David,

Here is a small example of custom sorting for the Image column:

void radGridView_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
{
    foreach (SortDescriptor descriptor in e.Template.SortDescriptors)
    {
        GridViewDataColumn column = e.Template.Columns[descriptor.PropertyName];
        if (column != null && column.DataType == typeof(Image))
        {
            Color color1 = ((Bitmap)e.Row1.Cells[descriptor.PropertyName].Value).GetPixel(0,0);
            Color color2 = ((Bitmap)e.Row2.Cells[descriptor.PropertyName].Value).GetPixel(0,0);
 
            e.SortResult = color1.ToArgb().CompareTo(color2.ToArgb());
            if (descriptor.Direction == ListSortDirection.Descending)
            {
                e.SortResult *= -1;
            }
        }
        else
        {
            e.Handled = false;
        }
    }
}
Kind regards,
Julian Benkov
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
GridView
Asked by
David
Top achievements
Rank 1
Answers by
AaronP
Top achievements
Rank 1
David
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or