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

Custom Sorting on one column

2 Answers 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 17 Feb 2020, 08:31 AM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Feb 2020, 12:19 PM
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.
0
Martin
Top achievements
Rank 1
answered on 19 Feb 2020, 01:56 PM
Thanks. I missed this part in the documentation, sorry.
Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Martin
Top achievements
Rank 1
Share this question
or