Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
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" >
      <DataGrid.Columns>
          <DataGridTextColumn Header="Employee Name" Binding="{Binding Path=eName}" Width="1*"   IsReadOnly="True" />
           <DataGridTextColumn Header="Department Name" Binding="{Binding Path=dName}" Width="1*"  IsReadOnly="True"  />
      </DataGrid.Columns>
</DataGrid>
 
<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">
</ListBox>

 

Any link, sample code, suggestion will be appreciated.
Regards,
Minal
Posted 11-Jul-13 6:49am
minalmt145
Comments
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 OriginalGriff 341
1 Marcin Kozub 225
2 Praneet Nadkar 197
3 Sergey Alexandrovich Kryukov 190
4 Shweta N Mishra 161
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
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