Click here to Skip to main content
14,124,474 members
Click here to Skip to main content
Add your own
alternative version

Stats

22K views
2.2K downloads
5 bookmarked
Posted 7 Aug 2014
Licenced CPOL

Reorder DataGrid/ListBox Items with Drag and Drop Wpf

, 7 Aug 2014
Rate this:
Please Sign up or sign in to vote.
The easy way to Reorder your DataGrid/ListBox with Drag and Drop

Introduction

Drag and Drop usually ameliorate our project spacially on terme of use and simplicity. 

Using the code

First of all , you need to add to the reference the dll GongSolutions.Wpf.DragDrop , it is already unclude on the Project after you downoad it.

Then we add the path of this dll in our MainPage.

 xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"

After we create our ListBox or DataGrid , we add  attributes dd:DragDrop.IsDragSource and  dd:DragDrop.IsDropTarget="True".

<ListBox Grid.Column="1" SelectionMode="Extended" ItemsSource="{Binding MSPCollection}"
 dd:DragDrop.IsDragSource="True" Width="300" Margin="0,0,5,0" dd:DragDrop.IsDropTarget="True">
...

After We Bind a List of Object to this Listbox we add two method DragOver and Drop.

Ps: You class should inherit the interface IDropTarget.

void IDropTarget.DragOver(DropInfo dropInfo)
       {

       }

void IDropTarget.Drop(DropInfo dropInfo)
       {

       }

History

Download this simple example to get the full project ;)

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Anis Derbel
Software Developer (Junior) Microsoft Student Partners
Tunisia Tunisia
I study Software Engineering , 23 years old , I'm motivated with all Technologies of Microsoft.
Since I have been in the Community of Microsoft as Microsoft Student Partners, I developped many apps on the platform Windows and Phone. Now , it's time to share what I learn here and I'am ready to help Everyone.
You can contact me at any time (anisderbel@outlook.com)
Group type: Organisation

9 members


You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
Unfug11-May-17 22:40
memberUnfug11-May-17 22:40 
QuestionInvalid Markup Pin
Bermudabob688-Dec-14 23:56
memberBermudabob688-Dec-14 23:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190518.1 | Last Updated 7 Aug 2014
Article Copyright 2014 by Anis Derbel
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid