Strategy for sorting GridViewComboBoxColumn by the DisplayMemberPath

8 posts, 0 answers
  1. Duncan
    Duncan  avatar
    13 posts
    Member since:
    Mar 2011

    Posted 26 Oct 2012 Link to this post

    I understand from scouring this forum that the GridViewComboBoxColumn does not sort by the DisplayMemberPath, it sorts by the DataMemberBinding which is essentially a property of the item the row is bound to.  You can set the SortMemberPath but again that is just a different property of the item the row is bound to, not a property of the GridViewComboBoxColumn ItemsSource.  With that said, the filter control displays the DisplayMemberPath and even sorts the items properly.

    I'm looking for a way to get the GridViewComboBoxColumn to sort on the DisplayMemberPath, but I do not want to code this for every single grid with custom sorting or every single GridViewComboBoxColumn I add to our application.  There are a number of developers on this project and undoubtedly one will forget to do it, and this is not really maintainable either.  

    Ideally I could have my own SortableGridViewComboBoxColumn I could use that inherited from the GridViewComboBoxColumn but I have not had much luck going down this road so far.  Is there any advice you can give or samples I can look at?  I've been through almost everything on this forum already.

    Thanks.


  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 29 Oct 2012 Link to this post

    Hello,

    Actually such a feature has already been implemented. You may find additional information in this forum thread. Please let me know in case you have any further questions.

    All the best,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Duncan
    Duncan  avatar
    13 posts
    Member since:
    Mar 2011

    Posted 29 Oct 2012 Link to this post

    Unfortunately that does not solve the sorting problem.  I do not have a problem with the filtering control, I have a problem with the sorting of the GridViewComboBoxColumn.  The default sort works off of the DataMemberBinding unless you set the SortMemberPath, but the SortMemberPath is simply another property on the object the row is bound to.  In your example the ViewModel is adding a new property called SortID and setting that for every object.  

    What happens if I add a new object to the collection?  Now I have to loop through the entire collection and set the "SortID" property for every combo box column in the grid.  Not elegant.

    I am looking for a way to get the control to sort by DisplayMemberPath so I don't need to create many many seperate properties for the grids in our application.  
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Oct 2012 Link to this post

    Hi,

    Indeed additional setting of the SortMemberPath will be needed. In order to avoid this, you could handle the Sorting event of the RadGridView and apply your custom sorting which sorts based on the DisplayMemberPath. You can check the CustomSorting WPF Demo and our online documentation for an example.

    Greetings,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Duncan
    Duncan  avatar
    13 posts
    Member since:
    Mar 2011

    Posted 30 Oct 2012 Link to this post

    As I explained in the first post I would rather not use custom sorting because I have to implement that on every GridViewComboBoxColumn in every grid inside the application, some of these columns are built dynamically as well which adds another layer of complexity.  I am looking for something generic that I can reuse over and over.

    Is there no way to inherit from the GridViewComboBoxColumn and write some generic code to sort?  That way we simply use this new column and the application will behave as all users would expect it to behave.
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 30 Oct 2012 Link to this post

    Hi,

    Unfortunately this is what we can suggest regarding Sorting of this column. Inheriting it will not help as the sorting logic is in the Data Engine, it is not in the column.  

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Anton
    Anton avatar
    11 posts
    Member since:
    Jun 2011

    Posted 10 Nov 2015 in reply to Duncan Link to this post

    Hi Duncan. Did you solve your problem? I have the same and don't know how to implement it via custom combobox column.
  9. Duncan
    Duncan  avatar
    13 posts
    Member since:
    Mar 2011

    Posted 10 Nov 2015 in reply to Anton Link to this post

    No, I never got it working.  I did try using a custom column but that had its own challenges.  What I typically do now is use a regular data column and change the cell edit template to a combo box.

Back to Top
UI for WPF is Visual Studio 2017 Ready