user2160375
user2160375

Reputation:

Drag and drop in WPF ListView

I'm using WPF ListView, where SelectionMode is set to Extended (you can select multiple items only with ctrl pressed). I need to implement D&D between two ListViews. To perform drag event, I used DragItem event in WinForms, but such an event is not provided in wpf. I've decided to use ListViewItem PreviewMouseDownClick

private void ListViewItemMouseDownClick(object sender, MouseButtonEventArgs e)
{
    if (!this.AllowDragDrop)
    {
        return;
    }

    DragDrop.DoDragDrop(
        ListViewItemsCollection, this.SelectedItems, DragDropEffects.Copy | DragDropEffects.Move);
}

Unfortunately such a solution has a bug: selecting single item (without ctrl pressed) works. However, I need to double-click to select item while ctrl is pressed in order to select multiple items. There is no difference when using ListView's PreviewMouseDown or ListViewItem's PreviewMouseDown. Any ideas how to solve problem?

Upvotes: 5

Views: 20334

Answers (1)

user2160375
user2160375

Reputation:

Found solution, works like a chram: social.msdn.microsoft.com. I joined it with code from moncadad's link. Thanks!

Upvotes: -2

Related Questions