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

Avoid auto sorting in RadGridView

3 Answers 363 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sandipa
Top achievements
Rank 1
Sandipa asked on 14 Feb 2014, 09:19 AM
I want to sort the grid only on Header click. In sorting when ever we modify the value of the sorted column the rows get auomatically sorted based on the value.
I just want to avoid this auto sorting during modifying the cell values, it should happen only on header click. Is this possible in RadGridView for win form ?

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Feb 2014, 04:16 PM
Hello Sandipa,

Thank you for writing.

Even if you remove the sort descriptors when a value is changed the original row appearance will occur. And the original data source row order will be restored. In general if you have a sort descriptor (when the user clicks the header cell such is created) the columns will be sorted by its criteria or if there is no sort descriptor the rows order will match the one from the data source. 

If you have any questions, please do not hesitate to contact us.

Regards,
Dimitar
Telerik
0
Göran
Top achievements
Rank 1
answered on 28 Oct 2014, 01:51 PM
Hi, is it possible to achieve the "sort only on header click" behavior. 
So the list is only sorted once when the user clicks on the header, new rows will be appended at the bottom and updated rows will not be auto sorted.
Regards
0
Dimitar
Telerik team
answered on 30 Oct 2014, 03:46 PM
Hi Goran,

Thank you for writing.

As mentioned in my previous post this is not supported in RadGridView, as in fact this is no longer sorting. Nevertheless you can disable the built-in sorting an handle the header cell click yourself. For example you can sort the underlying data source which will give you the desired functionality:
BindingList<MyTestClass> list = new BindingList<MyTestClass>();
void radGridView1_MouseClick(object sender, MouseEventArgs e)
{
    var element = radGridView1.GridViewElement.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
    if (element != null)
    {
        List<MyTestClass> sorted = list.OrderByDescending(x => x.value).ToList();
 
        BindingList<MyTestClass> source = new BindingList<MyTestClass>(sorted);
        radGridView1.DataSource = source;
    }
}

I hope this helps.

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Sandipa
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Göran
Top achievements
Rank 1
Share this question
or