none
Order Records

    Question

  • Say I have a topic that I have records pertaining too...Say its Lessons in a particular class, say Math
    for the most part I can set up the table to list these in the order they should be tought...
    Although this order is not set in stone...

    I could create an order ID number on the records in which to sort with no problem....
    BUT what I am looking for is creating the ability for the user to change this order.
    I have seen in many applications an arrow button that will allow the user to move that selected record up or down in the list.
    Would I try and changes that ID number in code by usign these arrows...

    Any thoghts on how to accomopish this?  Does that make sense?

     

    Tuesday, March 13, 2012 5:01 PM

Answers

  • My suggestion is add a sequence number property to your business object that you use for sorting.

    Then you can do the following:

    1) When loading the list to display, sort it based on the sequence number.
    When the user click a "move up" or "move down" button, reposition the item in the collection the control is bound to and also update the sequence numbers accordingly.

    2) Use a CollectionViewSource where you specify sorting based on the sequence number. Set the ItemsSource of your collection control to the View property of the CollectionViewSource.  Read about CollectionViewSource here.
    When the user clicks the "move up" or "move down" button, update the sequence numbers accordingly and the UI should be automatically updated. Optionally, you can call the CollectionViewSource.View.Refresh() method to manually force an update.

    Wednesday, March 14, 2012 7:07 AM
  • Hi,

    Thats sort of what I was thinking....anyone have any examples out there?

    Please check the blogs below which give you some samples about how to use CollectionViewSource to order records.

    http://weblogs.asp.net/psheriff/archive/2010/07/22/sort-data-using-code-with-the-silverlight-collectionviewsource.aspx

    http://www.codeproject.com/Articles/178011/Sorting-an-Observable-Collection-using-the-View-Mo

    Best wishes,

    Tuesday, March 20, 2012 3:15 AM

All replies

  • My suggestion is add a sequence number property to your business object that you use for sorting.

    Then you can do the following:

    1) When loading the list to display, sort it based on the sequence number.
    When the user click a "move up" or "move down" button, reposition the item in the collection the control is bound to and also update the sequence numbers accordingly.

    2) Use a CollectionViewSource where you specify sorting based on the sequence number. Set the ItemsSource of your collection control to the View property of the CollectionViewSource.  Read about CollectionViewSource here.
    When the user clicks the "move up" or "move down" button, update the sequence numbers accordingly and the UI should be automatically updated. Optionally, you can call the CollectionViewSource.View.Refresh() method to manually force an update.

    Wednesday, March 14, 2012 7:07 AM
  • Thats sort of what I was thinking....anyone have any examples out there?
    That example for the collection View Source is very similar to RIA service....could you use an RIA service?
    Thanks for your thoughts

    Wednesday, March 14, 2012 9:17 AM
  • Hi,

    Thats sort of what I was thinking....anyone have any examples out there?

    Please check the blogs below which give you some samples about how to use CollectionViewSource to order records.

    http://weblogs.asp.net/psheriff/archive/2010/07/22/sort-data-using-code-with-the-silverlight-collectionviewsource.aspx

    http://www.codeproject.com/Articles/178011/Sorting-an-Observable-Collection-using-the-View-Mo

    Best wishes,

    Tuesday, March 20, 2012 3:15 AM