Custom Sorting on one column

3 posts, 1 answers
  1. Martin
    Martin avatar
    17 posts
    Member since:
    Nov 2019

    Posted 17 Feb Link to this post

    Hi, i read the documentation for "custom-sorting" and "Setting Sorting Programmatically" but that´s not my case.

    i need a possibility to add a custom-sorting only for one column and sort with the data of a hidden column.

    What´s the right way to do that?

    Best regards

    Martin

  2. Answer
    Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3900 posts

    Posted 19 Feb Link to this post

    Hello, Martin,

    In the CustomSorting event the Handled argument of the GridViewCustomSortingEventArgs allows you to control whether the default sorting logic will control the sort order of the rows (by setting the Handled argument to false) or your custom logic will be applied (by setting the Handled argument to true) via setting the SortResult.

    The following code snippet demonstrates a sample approach how to apply custom sorting only for the ProductID column and leaжe the basic sorting for the rest of the columns:
            private void RadForm1_Load(object sender, EventArgs e)
            { 
                this.productsTableAdapter.Fill(this.nwindDataSet.Products);
                this.radGridView1.BestFitColumns();
    
                this.radGridView1.EnableCustomSorting = true;
                this.radGridView1.CustomSorting += radGridView1_CustomSorting;
            }
    
            private void radGridView1_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
            {
                if (this.radGridView1.SortDescriptors.Contains("ProductID"))
                {
                    //use custom sorting logic
                    e.Handled = true;
                    e.SortResult = e.Row1.Cells["ProductID"].Value.ToString().CompareTo(e.Row2.Cells["ProductID"].Value.ToString());
                }
                else
                {
                    //leave the basic sorting logic
                    e.Handled = false;
                }
            }

    Please refer to the following help article which demonstrates how to use the custom filtering logic: https://docs.telerik.com/devtools/winforms/controls/gridview/sorting/custom-sorting 

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Martin
    Martin avatar
    17 posts
    Member since:
    Nov 2019

    Posted 19 Feb in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks. I missed this part in the documentation, sorry.
Back to Top