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

Setting default sort on columns to descending

5 Answers 356 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 08 Jul 2011, 10:02 AM
Hi 

I have checked the forums, but not been able to find a definitive answer on this.

We are displaying data that shows the top ranking products across a number of different criteria (columns). We only ever want to see these in descending order. I have tried using the SortChanging and SortChanged events, but with no success.

Can you assist me?

Steve

5 Answers, 1 is accepted

Sort by
0
komathi priya
Top achievements
Rank 1
answered on 08 Jul 2011, 11:21 AM
hi steve,

You can sort the data in query itself by using "Order by Desc"  property in the the sql.

"select * from products order by ranking desc"
0
Steve
Top achievements
Rank 1
answered on 08 Jul 2011, 12:06 PM
Thanks for your help. 

I have resolved this in a slightly different way. Using the SortChanged event, I forced the sort direction to be descending. If anyone has a better suggestion, I'd be glad to hear from you.

Private Sub grdStyles_SortChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangedEventArgs) Handles grdStyles.SortChanged      
grdStyles.Columns(grdStyles.SortDescriptors(0).PropertyName).SortOrder = RadSortOrder.Descending
  
End Sub

0
Julian Benkov
Telerik team
answered on 13 Jul 2011, 04:02 PM
Hello Steve,

Thank you for contacting us.

The most suitable solution in your scenario is to use the SortChanging event and change the Direction only when it is Ascending:

Private Sub radGridView1_SortChanging(sender As Object, e As GridViewCollectionChangingEventArgs)
    Dim sortDescriptor As SortDescriptor = TryCast(e.NewItems(0), SortDescriptor)
    If sortDescriptor IsNot Nothing AndAlso sortDescriptor.Direction = ListSortDirection.Ascending Then
        sortDescriptor.Direction = ListSortDirection.Descending
    End If
End Sub

I hope you find this useful. Let me know if you have further questions.

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!

0
Murali
Top achievements
Rank 1
answered on 29 May 2013, 05:52 AM
Hi, 
How can i get the sortchanged and sortchanging events in radgrid control? in properties i cant find. I am using c#. Can any one suggests me .



Thanks & Regards,
K. Murali Krishna.
0
Stefan
Telerik team
answered on 31 May 2013, 02:57 PM
Hello Murali,

Both of the events are exposed on the control level. Please refer to the attached image. Perhaps, you have not selected the right control on the form, when you were looking for the events.
 

Regards,
Stefan
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
komathi priya
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Julian Benkov
Telerik team
Murali
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or