zzz6519003 / gong-wpf-dragdrop

Automatically exported from code.google.com/p/gong-wpf-dragdrop
1 stars 0 forks source link

Move only #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I really appreciate what you have done. I would like to use your project, but 
I haven't found the way how to only move items. Copy is no use for me.

Is it a unknown feature, or future feature, or not featured at all?

Original issue reported on code.google.com by kovm...@gmail.com on 14 Jan 2010 at 8:42

GoogleCodeExporter commented 9 years ago
I'm afraid I don't understand the problem. You can move items: if you want to 
move 
rather than copy it is simply a case of removing the item from the source 
collection as 
well as adding it to the target collection.

Or am I misunderstanding?

Original comment by gro...@gmail.com on 15 Feb 2010 at 7:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi Grokys,

Thanks for this nice component.

I have the same issue here (I want to move items from one treelist to another). 
And I
think it's quite easy to integrate it into your component:

In DefaultDragHandler add the following method:
/// <summary>
/// Performs after-drag processing at the source
/// </summary>
public virtual void Drag(DragInfo dragInfo, DropInfo dropInfo)
{
  // Remove the items in the source only with a move
  if ((dragInfo.Effects == DragDropEffects.Move) && (dragInfo.SourceCollection !=
dropInfo.TargetCollection))
  {
     IEnumerable data = ExtractData(dragInfo.Data);
     IList sourceList = GetList(dragInfo.SourceCollection);
     foreach (object o in data)
       {
          sourceList.Remove(o);
       }
  }
}

Also add this method to the interface

In DragDrop.cs add the following lines in DropTarget_PreviewDrop just before
e.Handled = true:
// Also perform after-drop processing in the source
DefaultDragHandler.Drag(m_DragInfo, dropInfo);

That's it,

Frank

Original comment by sportfr...@gmail.com on 4 May 2010 at 11:26

GoogleCodeExporter commented 9 years ago
I'm sorry I didn't react before. Thank you both for advices. I really 
appreciate it :-)

Original comment by kovm...@gmail.com on 4 May 2010 at 1:02

GoogleCodeExporter commented 9 years ago
Does this issue need any changes to the framework? I can't see that it does, so 
marking 
it Invalid for now.

Original comment by gro...@gmail.com on 4 May 2010 at 4:49

GoogleCodeExporter commented 9 years ago
It does need changes to your component (ao in DragDrop.cs) within method
DropTarget_PreviewDrop.

In my case I want to move children from root1 to the children list of root2. 

This is part of my application:
class MultiSelectTreeViewDragHandler : IDragSource
    {
        void IDragSource.StartDrag(DragInfo dragInfo)
DragDrop.DefaultDragHandler.StartDrag(dragInfo);
{
                // Only move allowed
                if ((dragInfo.Effects & System.Windows.DragDropEffects.Copy) ==
System.Windows.DragDropEffects.Copy)
                   dragInfo.Effects = System.Windows.DragDropEffects.Move;
}

Original comment by sportfr...@gmail.com on 4 May 2010 at 5:08

GoogleCodeExporter commented 9 years ago
Ah yes sorry, I overlooked that part of your message.

However, I can't see why this change is needed. When the item is dropped, you 
can get hold of a reference to 
the source collection using DropInfo.DragInfo.SourceCollection. 

So in the IDropHandler.Drop() method, you'd simply call:

    dropInfo.DragIndo.SourceCollection.Remove(item)

With the item that has been moved.

Would this not work?

Original comment by gro...@gmail.com on 4 May 2010 at 5:17

GoogleCodeExporter commented 9 years ago
Sorry, that should read:

     dropInfo.DragInfo.SourceCollection.Remove(item)

Original comment by gro...@gmail.com on 4 May 2010 at 5:18

GoogleCodeExporter commented 9 years ago
It probably will work, but it is not good design when the receiver also handles 
the
source (and what if one is copy and the other is move?).

I normally would use the Drop event, but you won't raise it.
See also http://msdn.microsoft.com/en-us/library/ms742859.aspx

Original comment by sportfr...@gmail.com on 4 May 2010 at 5:27

GoogleCodeExporter commented 9 years ago
Yes, I see your point. And thinking about it, my proposed solution won't work 
in the 
case that a ViewModel exposes a read-only wrapper around an internal collection 
(such 
as a ReadOnlyObservableCollection) either.

Count me convinced - I will add this functionality shortly.

Original comment by gro...@gmail.com on 4 May 2010 at 5:42

GoogleCodeExporter commented 9 years ago
Ok, I've added a Dropped method to the IDragSource interface which is called 
when a drop has taken place. Assuming you're still interested in this change 
(sorry it's taken so long) could you take a look and see if it fits your 
requirements?

Please note that I've committed a breaking change to SVN in that the dragInfo 
and dropInfo parameters to the drag and drop handlers are now interfaces rather 
than concrete classes (to allow easier unit testing).

Original comment by gro...@gmail.com on 13 Jul 2010 at 7:42

GoogleCodeExporter commented 9 years ago
:-) ... thanks a lot :-) ... appreciate it :} ...

There were some more important issues I had to work on, so I put D&D on ice for 
a while. I'll give it a shot as soon as possible.

Thanks a lot again :-)

Original comment by kovm...@gmail.com on 14 Jul 2010 at 8:25