views:

103

answers:

1

I have a collection that is binded to my Listview.

I have provided options to user to "move up" "move down" the selected item in the list view. I have binded the selected item of the listview to my viewmodel, hence I get the item in the collection on which user want to do the operation.

I have attached "move up" "move down" commands in my viewmodel.

I want what is the best way to move up and down in the collection in the collection which is reflected in the list view.

For example

If the selected item is the last item in the collection ( and in the list view) move the item to the top.

For this I have to create a new collection and reorder the items in the collection.

Please suggest.

+1  A: 

You can do this by retrieving the index of the ObservableCollection corresponding to the selected item and swapping it with the previous item.

Veer
Thanks Veer!! I really appreciate if you please give me the code snippet.. Thanks again
Ashish Ashu
When you say you already have binded your selected item with your viewmodel, then you have the index of the item to be moved. I don't know where you want to move this item. If you know the destination index, you can move all the items inbetween below if moveUp and vice versa and then put the selected item into the destination index. If this is not what you asked for, then tell me specifically which code snippet you want.
Veer
Thanks Veer , I found my mistake .. Thanks for the solution
Ashish Ashu
You can also update your question with "Where you went wrong" and "how you solved it", if you wish :)
Veer