For whatever reason, i cannot get it to auto-sort by clicking on the column headers. (My understanding after reading the Help is that this should be automatic if the "GridView.EnableSorting" and "GridView.MasterTemplate.EnableSorting" properties are both true). I do have AutoGenerateColumns also set to True, since the business object is still evolving and gaining/adding/changing properties in between builds..
I've tried setting the grid's DataSource property directly to the ObservableCollection<MyObjectType>. I've tried creating an intermediate BindingSource and setting the grid's DataSource to that. I've tried creating several SortDescriptors for the columns on which I most need to sort. I've tried removing all such SortDescriptors. I've tried creating a custom SortableObservableCollection (which works in binding in WPF) instead of the ObservableCollection. Etc.
The data always displays correctly in the GridView; but doesn't sort or show sort direction indicators in the column headers.
There has to be something simple I'm missing.
Thanks!
-Bob
6 Answers, 1 is accepted
I was creating the collections via a constructor that takes a generic List<T> as the input. I knew that the standard .Net List<T> does not support auto-sorting in a gridview. I thought that the Collection types I was creating from the list; particularly the constructor for SortableObservableCollection<T> (which I have been using in WPF) would take care of that limitation. That was incorrect.
The fix was to go out on the web, find a SortableBindingList<T>, and create that as the original list instead.
-Bob
The Winforms RadGridView control can bind to IList, IEnumerable objects and supports the sorting operation internally using its data structures and binary tree. The RadGridView control does not make the sorting operation in an external bound object. You can bind to generic List<T>, ObservableCollection<> or any IList or IEnumerable object and the sorting operation must work by default.
I hope this information is useful. Let me know if you need further assistance.
Julian Benkov
the Telerik team
Hello, Jay,
By design, RadGridView supports sorting functionality out of the box. It is expected to sort the rows displayed in the grid UI. The underlying DataSource collection is not affected. RadGridView internally uses a RadListSource which actually manages the sorting, filtering, grouping operations. That is why there Rows and ChildRows collections are grid level: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/rows-vs-childrows
If this default behavior doesn't fit the exact goal you are trying to achieve, it would be great if you share with us more details about the case you need to cover. Thus, we would be able to get better understanding of the precise case and think about an appropriate solution.
At the beginning of this thread, I described the property settings and steps I took to try to get the Grid to support auto-sorting by clicking on the column header.
What types of property settings or missing code on my part could have caused such a sort feature to not work until i rebound to a different type of collection?
Thanks!
-Bob
The sorting operation is enabled by default in RadGridView control and it can sort items from a generic List<T> collection. If you continue to experience the issue, please send us the implementation of the used business objects and some part of your data to investigate the issue locally. Thank you for your cooperation.
All the best,Julian Benkov
the Telerik team
I am binding to grid in this way:
DataManager dm = new DataManager();
.DataSource = dm.getLoadGroupList();
Where this in turn calls:
internal List<GroupListModel> getLoadGetGroupList()
{
List<GroupListModel> GroupListModelList = new List<GroupListModel>();
try
{
var results = from vw_PS10_Group_List in _gridDataContextObj.vw_PS10_Group_List
select vw_PS10_Group_List;
if (results != null)
{
foreach (var item in results.ToList())
{
GroupListModel glm = new GroupListModel();
glm.WSEC_GRP_DESC = item.WSEC_GRP_DESC;
glm.WSEC_GRP_NAME = item.WSEC_GRP_NAME;
GroupListModelList.Add(glm);
}
}
}
catch (Exception ex)
{
return null;
}
return GroupListModelList;
}
The sorting / filtering does not work, please help me urgently.
Thanks
I had accidentally EnableCustomSorting and EnableCustomFiltering turned on. Which was causing the problem.
Thanks!