locked
Update sorting on ListView RRS feed

  • Question

  • Hi,

     

    I have a ListView which I sort using Items.SortDescription on. But when I update data on the underlying collection the sorting doesn't appear to update accordingly. I have to manually "resort" in order for the order to be refreshed.

     

    Say for example that I have a column called "Name" which I sort by in ascending order.

    When I rename Zebra to Ape I want to it jump to the first spot, instead it stays in its original place.

     

    Thanks!

    Tuesday, January 18, 2011 12:33 AM

Answers

All replies

  • Ephracis,

    My ListView sorts just fine. For the item to refresh the Layout and go to its correct place, you need to have used objects that implement INotifyPropertyChanged (which will signal the UI to refresh the Layout). Since you have provided no other information, I think that is the cause. You can manually do this by using myListView.UpdateLayout().

     

    Good luck.


    noorbakhsh حميد نوربخش
    Tuesday, January 18, 2011 5:43 AM
  • The source is implementing INotifyPropertyChanged. The ListViewItem is updated accordingly, showing the new data. It's just that the sorting isn't updated: the ListViewItem isn't moved within the ListView. It's just updated.

     

    I guess I can always remove the sorting from SortDescriptions and add it again.

    Tuesday, January 18, 2011 2:55 PM
  • I am using an ObservableCollection and binding to the ItemSource and all is fine. I guess as you have said, you can clear the SortDescription and add it again, but you really should not have to.

    Sorry I can not help beyond this.


    noorbakhsh حميد نوربخش
    Tuesday, January 18, 2011 3:43 PM
  • I am also using an ObservableCollection in which I have implemented the INotifyPropertyChanged interface which I use to send notifications to the ListView when certain properties are updated.

     

    Strange, but removing and inserting the SortDescription work at least. It gave me two lines of code instead of one, though. :P

    • Marked as answer by Ephracis Saturday, February 12, 2011 5:46 PM
    Tuesday, January 18, 2011 4:01 PM
  • Hi Ephracis,

    Based on your description, I think you could try to use "UpdateSourceTrigger=PropertyChanged".

    If your issue persists, could you share me some codes or a simple sample to reproduce your issue, I think it will be very helpful for me to find the root cause of your issue.

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 20, 2011 12:04 PM
  • Hi Ephracis,

    I think xkrja has provided a solution for your issue, you could refer to this link:

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cb7c5c62-7ca9-49b5-91a0-379581b1c1aa/

     

    Best regards,


    Sheldon _Xiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Sheldon _Xiao Sunday, February 13, 2011 3:53 AM
    • Marked as answer by Sheldon _Xiao Wednesday, March 2, 2011 9:06 AM
    Sunday, February 13, 2011 3:53 AM