This is a migrated thread and some comments may be shown as answers.

DragandDrop between 2 ListBoxes

0 Answers 51 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Inq asked on 15 May 2012, 01:05 PM
I have a question/problem with DragAndDrop and listBoxes.
I have two collections:
   var coll1 = new ObservableCollection<User>() {new User() {Id = 1}, new User() {Id = 2}};
  var coll2 = new ObservableCollection<User>() { new User() { Id = 2 }, new User() { Id = 4 } };


I can  copy some items from listbox1 to listbox2 via draganddrop, but when i want to drag from listbox1 to listbox2 item User(id=2) I put listbox2.AllowDrop= false, because i don't want that listbox2 contains two equal items User(id=2)

So it works, but i want more ;) I want to show why it is impossible to drop item to listbox.

        private void OnDragInitialize(object sender, DragInitializeEventArgs e)
            e.AllowedEffects = DragDropEffects.Copy;
            var data = ((FrameworkElement)e.OriginalSource).DataContext;
            e.DragVisual = new DragVisual()
                Content = data,
                ContentTemplate = this.Resources["DragTemplate"] as DataTemplate
            DataObject dataObject = new DataObject();
            dataObject.SetData("DragData", data);
            dataObject.SetData("Text", data.ToString());
            e.Data = data;

I want to show something like this link

Thanks in advance!

No answers yet. Maybe you can help?

Asked by
Top achievements
Rank 1
Share this question