Click here to Skip to main content
11,709,220 members (49,259 online)
Rate this: bad
Please Sign up or sign in to vote.
I am looking for some help implementing two way drag and drop functionality between ListBox and DataGrid column in WPF. i have searched through the net and managed to grab drag-drop samples but they don't fulfill my needs, plus most of them are having some missing codes. My datagrid contains two columns say EmployeeName and DepartmentName. These values are coming from collection which is initially loaded with EmployeeName only. which means departmentname column is blank. User can then select the appropriate department using drag-drop. Department names are loaded in Listbox. Departmentname is required to be selected from Listbox, draged and droped in to datagrid column. with that Employeename will be mapped to department name. Once dropped, that department name should be removed from listbox so that it can't be mapped against another employee. Mapping can be altered by dragging the department name back to the listbox from datagrid and re-selecting another departmentname for drag-drop.

My Xaml is something like this. (it is not actually employee/department in the code but i have used that to explain what i am looking for)

<DataGrid x:Name="DatagridEmployeeMapping"  Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,5,5,5" 
         ItemsSource="{Binding ElementName=MWindow, Path=Settings.EmployeeMapping}" GridLinesVisibility="Vertical" AutoGenerateColumns="False" CanUserAddRows="False" IsReadOnly="False" SelectionMode="Single" >
          <DataGridTextColumn Header="Employee Name" Binding="{Binding Path=eName}" Width="1*"   IsReadOnly="True" />
           <DataGridTextColumn Header="Department Name" Binding="{Binding Path=dName}" Width="1*"  IsReadOnly="True"  />
<ListBox x:Name="ListboxDepartmentData" Grid.Column="2" Grid.Row="1"  Margin="5,5,5,5" 
        ItemsSource="{Binding ElementName=MWindow, Path=DepartmentDetails}" DisplayMemberPath="Name" ScrollViewer.VerticalScrollBarVisibility="Visible">

Any link, sample code, suggestion will be appreciated.
Posted 11-Jul-13 5:49am
vasim sajad at 26-Nov-13 1:22am
did u found any solution ? me too want this thing..

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 580
1 OriginalGriff 250
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,027
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100