views:

456

answers:

2

Using C# and the .Net framework 2.0. I have an MDI application and need to handle dragover/dragdrop events. I have a list docked to the left on my application and would like to be able to drag an item from the list and drop it in the MDI client area and have the correct MDI child for the item open. I can't seem to figure out where to attach the handler. I've tried attaching to the main form's events and the MdiClient that is part of the form, but neither event handler seems to get called when I expect them to.

I'm also using an Infragistics Tabbed MDI Manager, so I'm not sure if that's affecting it.

+1  A: 

I have an application that implements the Infragistics MDI DockManager (not Tabbed MDI), but I think those are very similar. It should work when you handle the MDI form events.

  • MDIForm.AllowDrop is set to true?
  • Is the object you're trying to drag serializable?
  • Try the DragEnter event instead of DragOver

As a last resort: if everything else fails, try contacting Infragistics Support.

Vincent Van Den Berghe
A: 

This code worked for me. It opens a new MDI child on dropping some text on MDI parent form.

...
using System.Linq;
...

public partial class Form1 : Form
{
    MdiClient mdi_client;
    public Form1()
    {
        InitializeComponent();
        mdi_client = this.Controls.OfType<MdiClient>().FirstOrDefault();
        mdi_client.AllowDrop = true;
        mdi_client.DragEnter += Form1_DragEnter;
        mdi_client.DragDrop += Form1_DragDrop;
    }

    private void Form1_DragDrop(object sender, DragEventArgs e)
    {
        myForm m = new myForm();
        m.Text = (string)e.Data.GetData(typeof(string));
        m.MdiParent = this;
        m.Show();
        m.Location = mdi_client.PointToClient(new Point(e.X, e.Y));
    }

    private void Form1_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.All;
    }
}
Shlomi Loubaton