• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

AaronReams ListView to ListView drag and drop as something that can be inherited?!

I'm using VS2005 and have a C# inheritance question for listview drag and drop abilities.  AaronReams provided a nice drag and drop bit from listview to listview and that is what I need.  It is entitled "Drag and drop jumpstart".   I have several mdi child forms in my app and all of them have two listviews that need this ability so I'd like each listview to inherit the ability.  How does that work?  I understand the concept but creating something that can be inherited is somehow beyond my grasp.  

Please - can someone put AaronReams listview to listview drag and drop code into a form that can be inherited?  I've been beating my head against my desk for like two days on this one!  If I see what I have and then the answer - man - that would be soooooo nice!

Thanks!

Will
0
wpm0001
Asked:
wpm0001
  • 4
  • 3
1 Solution
 
Bob LearnedCommented:
Well, let's look at the requirements to start with:

1) Set AllowDrop = True

2) Process MouseMove to see if the left button is down to begin drag/drop operation

3) Set the e.Effect in the DragOver event handler

4) Handle the DragDrop event

Is there anything missing in that list?

Bob
0
 
wpm0001Author Commented:
Hi TheLearnedOne
Well, other than removing the dragged listitems from the source listview I think that is all.  Man - sure sounds easy when you type it...
0
 
wpm0001Author Commented:
LearnedOne,

Were those four points intended to be a solution to creating a listview custom control with drag drop functionality that can be inherited?

Just Checking...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
wpm0001Author Commented:
No insult intended Bob.  My initial question was a rambling one because I was a bit frustrated with this inheritance thing.

If I ticked you off please let me know and I'll award the points out of pure shame...

Will
0
 
Bob LearnedCommented:
Will,

I had other things to take care, and no real time to provide an answer.  Here is an example of what I mean:

using System;
using System.Windows.Forms;

public class DragDropListView : ListView
{

    public DragDropListView()
    {
        // Allow drops on this control.
        this.AllowDrop = true;

        // Attach event handlers.
        this.DragDrop += new DragEventHandler(OnControlDragDrop);
        this.DragOver += new DragEventHandler(OnControlDragOver);
        this.MouseMove += new MouseEventHandler(OnControlMouseMove);
    }

    /// <summary>
    /// Handle when a ListViewItem is dragged and dropped onto this control from
    /// another DragDropListView control.
    /// </summary>
    private void OnControlDragDrop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(typeof(ListViewItem)))
        {
            ListViewItem item = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
            this.Items.Add(item);
        }
    }

    /// <summary>
    /// Handle giving feedback when a drag drop operation is over this control.
    /// </summary>
    private void OnControlDragOver(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Copy;
    }

    /// <summary>
    /// Handle when the mouse is moved while the left button is pressed to start
    /// a drag drop operation.
    /// </summary>
    private void OnControlMouseMove(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left && this.SelectedItems.Count > 0)
        {
            this.DoDragDrop(this.SelectedItems[0], DragDropEffects.Copy);
        }
    }

}

Bob
0
 
wpm0001Author Commented:
Hey Bob - This really helps!

Your example doesn't actually work but the comments are great!

As far as a beginning of understanding goes this is gold.  I don't know why I couldn't "get" this reading a book.  I used to be a pretty good at applying reading to reality...

Any idea why the drop item throws an exception?

Will
0
 
Bob LearnedCommented:
What exception did you get?

Bob
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now