WinForms RadGridView does not sort

7 posts, 1 answers
  1. BRiddle
    BRiddle avatar
    24 posts
    Member since:
    Sep 2010

    Posted 27 May 2011 Link to this post

    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
  2. BRiddle
    BRiddle avatar
    24 posts
    Member since:
    Sep 2010

    Posted 27 May 2011 Link to this post

    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
  3. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 02 Jun 2011 Link to this post

    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.
  4. BRiddle
    BRiddle avatar
    24 posts
    Member since:
    Sep 2010

    Posted 02 Jun 2011 Link to this post

    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
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 08 Jun 2011 Link to this post

    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.
  6. Michael
    Michael avatar
    2 posts
    Member since:
    Feb 2013

    Posted 27 Oct 2013 Link to this post

    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
  7. Answer
    Michael
    Michael avatar
    2 posts
    Member since:
    Feb 2013

    Posted 27 Oct 2013 Link to this post

    Ah the problem was solved.
    I had accidentally EnableCustomSorting and EnableCustomFiltering turned on. Which was causing the problem.
    Thanks!
Back to Top