Setting default sort on columns to descending

6 posts, 0 answers
  1. Steve
    Steve avatar
    4 posts
    Member since:
    Mar 2011

    Posted 08 Jul 2011 Link to this post

    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
  2. komathi priya
    komathi priya avatar
    30 posts
    Member since:
    Apr 2010

    Posted 08 Jul 2011 Link to this post

    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"
  3. Steve
    Steve avatar
    4 posts
    Member since:
    Mar 2011

    Posted 08 Jul 2011 Link to this post

    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

  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 13 Jul 2011 Link to this post

    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!

  5. Murali
    Murali avatar
    2 posts
    Member since:
    Apr 2013

    Posted 29 May 2013 Link to this post

    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.
  6. Stefan
    Admin
    Stefan avatar
    2911 posts

    Posted 31 May 2013 Link to this post

    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?
Back to Top