Multiple items from different List view Drag drop in WPF

RamG2022 1 Reputation point
2022-01-19T09:21:31.257+00:00

In a wpf application i have multiple ListViews. In one work flow i have to select multiple items from different list views and drag and drop all the items to another control.

Muliple items from a single list view is impletemented as below. Can anyone please suggest if there is a possibility to select multiple items from different list view

XAML

<ItemsControl Name="groupsTab" ItemsSource="{Binding Stores}" Margin="0,0,10,10" >
<ItemsControl.ItemTemplate >
<DataTemplate>
<GroupBox Name="groupsGroupBox" AllowDrop="True" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ScrollViewer.IsDeferredScrollingEnabled="True" Margin="0,0,10,10">
<GroupBox.Header>
<TextBlock Text="{Binding StoreName}" FontWeight="Bold" PreviewMouseDown="BeatHeaderClick" />
</GroupBox.Header>
<GroupBox.Content>
<ItemsControl ItemsSource="{Binding Branches}" Height="{Binding Path=GridHeight}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost='True'/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<GroupBox BorderThickness="1" Width="190" Visibility="{Binding Visibility}" BorderBrush="Black">
<GroupBox.Header>
<TextBlock FontWeight="Bold" MaxWidth="160" Drop="ControlItem_Drop" MouseLeftButtonDown="ControlItem_PreviewMouseMove"
Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" AllowDrop="True"
Foreground="{Binding Foreground}" Background="{Binding Background}">
</TextBlock>
</GroupBox.Header>
<ListView ItemContainerStyle="{StaticResource myListviewStyle}" Grid.Row="1" Visibility="{Binding Visibility}" SelectionChanged="LstView_SelectionChanged"
Width="180" MinHeight="30" SelectionMode="Extended"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled" Margin="0,0,0,0" BorderThickness="0"
MouseWheel="OnMouseWheelChanged" AllowDrop="True" Drop="TransferUnitToDiffStation" PreviewMouseLeftButtonDown="ListView_PreviewMouseLeftButtonDown"

                                                                  >
                                                            <ListView.ItemsSource>
                                                                <cad:ShapedCollection Source="{Binding Path=StaffDetails}" Where="IsVisible == true"/>
                                                            </ListView.ItemsSource>
                                                            <ListView.View>
                                                                <GridView  ColumnHeaderContainerStyle="{StaticResource GridHeaderStyle}">
                                                                    <GridViewColumn  Width="120" DisplayMemberBinding="{Binding Name}"></GridViewColumn>
                                                                    <GridViewColumn Width="35" DisplayMemberBinding="{Binding Gender}"></GridViewColumn>
                                                                    <GridViewColumn Width="35" DisplayMemberBinding="{Binding Age}"></GridViewColumn>
                                                                </GridView>
                                                            </ListView.View>
                                                        </ListView>
                                                    </GroupBox>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </GroupBox.Content>
                                </GroupBox>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>

xaml.cs

private void ListView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
try
{

            DragDrop.DoDragDrop(sender as DependencyObject, storeData, DragDropEffects.All);
        }
        catch (Exception ex)
        {
            Log.PrintError("Exception is thrown in ListView_PreviewMouseLeftButtonDown() " + ex.Message + "\n Error Details " + ex.StackTrace);
        }

    }
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
{count} votes