开发者

Using CTRL key to select mulitple rows to drag drop from one datagrid to another datagrid in silveright 4

开发者 https://www.devze.com 2023-03-26 17:17 出处:网络
I have silverlight application developed in Silverlight Version: 4.0.60531.0. In one page i have 2 datagrids. I have enabled DataGridDragDropTarget for both the datagrids.

I have silverlight application developed in Silverlight Version: 4.0.60531.0. In one page i have 2 datagrids. I have enabled DataGridDragDropTarget for both the datagrids.

If i use CTRL key to select random rows and drag drop, it wouldn't work. Please let me know what i'm missing in below xaml. Thanks in advance.

Below 2 scenarios it is working fine.

  1. Drag one row at a time
  2. Using SHIFT key and selecting multiple rows,it is working fine.
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:tk="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Toolkit"

    <tk:DataGridDragDropTarget   AllowDrop="True" Grid.Row="0" HorizontalAlignment="Left" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Center" > 
        <sdk:DataGrid  x:Name="d1" ItemsSource="{Binding}" AutoGenerateColumns="False" SelectionMode="Extended"> 
            <sdk:DataGrid.Columns> 
                <sdk:DataGridTextColumn Header="Number"  IsReadOnly="True" Binding="{Binding Path=No}" /> 
                <sdk:DataGridTextColumn Header="Name"  IsReadOnly="True" Binding="{Binding Name}" /> 
            </sdk:DataGrid.Columns>开发者_开发技巧; 
        </sdk:DataGrid> 
    </tk:DataGridDragDropTarget>


    <tk:DataGridDragDropTarget  AllowDrop="True" Grid.Row="1" HorizontalAlignment="Left" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Center" > 
        <sdk:DataGrid  x:Name="d2" Height="100" Grid.Row="1" SelectionMode="Extended" ItemsSource="{Binding}" AutoGenerateColumns="False"> 
            <sdk:DataGrid.Columns> 
                <sdk:DataGridTextColumn Header="Number"  IsReadOnly="True" Binding="{Binding Path=No}" /> 
                <sdk:DataGridTextColumn Header="Name"  IsReadOnly="True" Binding="{Binding Name}" /> 
            </sdk:DataGrid.Columns> 
        </sdk:DataGrid> 
    </tk:DataGridDragDropTarget>


The problem isn't so much multiple selection using the Ctrl key. If you release the Ctrl key during the drag-and-drop operation, you should find that the drag-and-drop operation completes successfully. It's more to do with dropping the items with Ctrl held down. Apparently, this indicates that you want to copy the items instead of move them.

I don't know of any documentation to back me up on this, but I did find the following in a documentation comment on an internal class (Microsoft.Windows.DragOperation, method GetDragDropEffects):

    /// <summary>
    /// Returns the allowed effects by analyzing the state of the keys 
    /// pressed.  If the control key is pressed the user is requesting a 
    /// copy. If copy is available the effect will be only copy, if not 
    /// available the effect will be None.
    /// </summary>

I added the property AllowedSourceEffects="Copy" to both of your DataGridDragDropTargets, and then I found that the drag-and-drop functionality stopped working altogether. However, when I changed these properties to AllowedSourceEffects="Copy,Move", I found that drag-and-drop worked again, including when I held the Ctrl key down. However, even when I held the Ctrl key down, the items were moved instead of copied.

0

精彩评论

暂无评论...
验证码 换一张
取 消