---
title: "Sorting a ListBox in WPF"  
description: "Sorting a ListBox in WPF"  
author: "Anonymous User"  
published: 2013-07-18  
updated: 2013-07-18  
canonical: https://www.mindstick.com/forum/1306/sorting-a-listbox-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# Sorting a ListBox in WPF

Hi [mindstick](https://yourviews.mindstick.com/view/84668/how-mindstick-is-used-for-marketing-purposes)!

Let me start off by saying that I am completely new with WPF (this is my first [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) 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 ListBoxes that are being bound to ObservableCollections from a [LINQ](https://www.mindstick.com/articles/12007/language-integrated-query-linq-queries) queries. In the beginning, everything is fine, all three are populated correctly. My [client](https://www.mindstick.com/articles/23198/3-steps-to-ensure-that-your-client-portal-is-impeccable) needs to [drag and drop](https://www.mindstick.com/forum/454/how-to-drag-and-drop-multiple-image-from-one-canvas-to-onther-canvas-in-html5) selections from one [ListBox](https://www.mindstick.com/articles/626/listbox-events-in-c-dot-net) to another. I also have this working, but when I do the drag and drop, the new [selection](https://www.mindstick.com/blog/60/populate-records-in-second-listbox-according-to-the-selection-in-first-list-box) 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](https://www.mindstick.com/articles/52/creating-timer-at-runtime-in-c-sharp-dot-net) through [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind) after the drag and drop [operation](https://www.mindstick.com/forum/33917/how-to-callback-operation-using-delegate-in-c-sharp) is complete.

Thanks!

## Replies

### Reply by shreesh chandra shukla

Solution!

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`](http://msdn.microsoft.com/en-us/library/system.windows.data.collectionview.aspx) to wrap your collections, set it up to do the sorting, and bind the ListBoxes to that.


---

Original Source: https://www.mindstick.com/forum/1306/sorting-a-listbox-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
