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

WinForms RadGridView does not sort

6 Answers 454 Views
GridView
This is a migrated thread and some comments may be shown as answers.
BRiddle
Top achievements
Rank 1
BRiddle asked on 27 May 2011, 06:17 PM
I have what I hope is a simple problem.   I have a simple WinForms application in which I'm providing a generic ObservableCollection<> of a simple public business object type as a data source for a RadGridView (version Winforms 2011_1_11_419), .  

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

Sort by
0
BRiddle
Top achievements
Rank 1
answered on 27 May 2011, 07:16 PM
Never mind.  As I had suspected, it was something simple.   I guess I've been spending too much time with WPF instead of WinForms.

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
0
Julian Benkov
Telerik team
answered on 02 Jun 2011, 08:49 AM
Hi 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.

Best wishes,
Julian Benkov
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
Jay
Top achievements
Rank 1
Iron
Iron
commented on 10 Jun 2023, 03:18 AM

You’re wrong. Radgridview will not support the underlying List<>. I’ve been dickin’ around with this for hours. I will just have to write a sort to sort the underlying data source, which makes the sort functionality of the grid a bit worthless..
Dess | Tech Support Engineer, Principal
Telerik team
commented on 14 Jun 2023, 03:30 PM

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.

0
BRiddle
Top achievements
Rank 1
answered on 02 Jun 2011, 02:36 PM
You're saying then that the RadGridView should have supported column-header-click re-sorting when bound to a plain, .Net 4.0, generic list<T> property in the parent Window instance?   It definitely did not do so for me.

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
0
Julian Benkov
Telerik team
answered on 08 Jun 2011, 08:29 AM
Hi 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
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Michael
Top achievements
Rank 1
answered on 27 Oct 2013, 11:54 AM
Hi,

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
0
Accepted
Michael
Top achievements
Rank 1
answered on 27 Oct 2013, 12:32 PM
Ah the problem was solved.
I had accidentally EnableCustomSorting and EnableCustomFiltering turned on. Which was causing the problem.
Thanks!
Tags
GridView
Asked by
BRiddle
Top achievements
Rank 1
Answers by
BRiddle
Top achievements
Rank 1
Julian Benkov
Telerik team
Michael
Top achievements
Rank 1
Share this question
or