Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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.
vasim sajad 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)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900