tags:

views:

435

answers:

1

Hello all.

Let me start off by saying that I am completely new with WPF (this is my first project and I have been working in it for less than a week). With that being said, please be easy on me!

I have three list boxes that are being bound to ObservableCollections from a LINQ queries. In the beginning, everything is fine, all three are populated correctly. My client needs to drag and drop selections from one listbox to another. I also have this working, but when I do the drag and drop, the new selection is placed at the bottom of the listbox instead of being sorted alphabetically with the existing items.

How can I sort the listbox at runtime through code behind after the drag and drop operation is complete.

Thanks!

+2  A: 

It is not entirely clear how you handle drag and drop in your code. You say that your ListBoxes are all data-bound - which implies that you actually move items from one backing collection to another on drag and drop. If so, ListBox just displays the items in order they are present in the collection. You should either sort them there, or, if sorting is a view-only behavior in your case (i.e. items are actually unordered in data model, by design), you should use CollectionView to wrap your collections, set it up to do the sorting, and bind the ListBoxes to that.

Pavel Minaev
Your assumptions are correct, and I will give this a try when I have a chance. Thanks!!
darthnosaj