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

Drag from RadMenuItem

5 Answers 88 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 07 Dec 2015, 06:41 PM

I create a RadMenu in a MDI Parent form dynamically.  Each menu item has a tag property with a value that references a string.  I also have a form that is open that has a Split Container, Panel and within the panel, a Panorama object with a PanelGroup, ready to add a tile.  I would like to drag from the RadMenuItem and drop into the PanelGroup and create a tile that has a reference (can also be the Tile's tag).  

 I already have this working when I drag from a TreeView to create a tile, as well as dragging from a desktop shortcut...   Although I can set the RadMenuItem.AllowDrag property = true, I don't see anyway to trigger and work with this...

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 08 Dec 2015, 12:27 PM
Hello Laura,

Thank you for writing.

The following example shows how you can perform a drag and drop operation between RadMenu and RadPanorama:
public Form1()
{
    InitializeComponent();
    foreach (var item in radMenu1.Items)
    {
        item.AllowDrag = true;
        item.MouseDown += Item_MouseDown;
        
    }
 
    radPanorama1.AllowDrop = true;
    radPanorama1.DragDrop += RadPanorama1_DragDrop;
    radPanorama1.DragEnter += RadPanorama1_DragEnter;
}
 
private void RadPanorama1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}
 
private void RadPanorama1_DragDrop(object sender, DragEventArgs e)
{
    RadMenuItem draggedItem = e.Data.GetData(typeof(RadMenuItem)) as RadMenuItem;
    RadTileElement tile = new RadTileElement();
    tile.Text = draggedItem.Text;
    radPanorama1.Items.Add(tile);
}
 
private void Item_MouseDown(object sender, MouseEventArgs e)
{
    var item = sender as RadMenuItem;
    radMenu1.DoDragDrop(item, DragDropEffects.Move);
}

Could you please check and let me know how it fit's in your case?

I am looking forward to your reply.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Laura
Top achievements
Rank 1
answered on 09 Dec 2015, 07:07 PM
This allowed me to drag/drop perfectly, but I have a residual problem in that now the click event is not firing.  On the menu item click event, I have a form opening.  This is not occurring when I have the DoDragDrop coded.
0
Dimitar
Telerik team
answered on 10 Dec 2015, 09:25 AM
Hello Laura,

Thank you for writing back.

You can start the drag drop in the MouseMove event instead:
private Point mouseDownPosition;
 
private void Item_MouseDown(object sender, MouseEventArgs e)
{
    this.mouseDownPosition = e.Location;
}
 
void item_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button != MouseButtons.Left)
    {
        return;
    }
    if (IsRealDrag(mouseDownPosition, e.Location))
    {
        var item = sender as RadMenuItem;
        radMenu1.DoDragDrop(item, DragDropEffects.Move);
    }
}

Please let me know if there is something else I can help you with. 
 
Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Laura
Top achievements
Rank 1
answered on 10 Dec 2015, 03:42 PM

I am getting an error on the IsRealDrag method - does not exist in the current context...  here is my code (where loNew = the RadMenuItem and mainMenuStrip is the RadMenu object):

 private void loNew_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (IsRealDrag(mouseDownPosition, e.Location))
            {
                var item = sender as RadMenuItem;
                mainMenuStrip.DoDragDrop(item, DragDropEffects.Move);
            }

        }

0
Dimitar
Telerik team
answered on 10 Dec 2015, 04:02 PM
Hello Laura,

Apparently I haven't copied the entire snippet. Here is the method:
private static bool IsRealDrag(Point mousePosition, Point initialMousePosition)
{
    return (Math.Abs(mousePosition.X - initialMousePosition.X) >= SystemInformation.DragSize.Width) ||
           (Math.Abs(mousePosition.Y - initialMousePosition.Y) >= SystemInformation.DragSize.Height);
}

Let me know if you have additional questions.

Regards,
Dimitar
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Menu
Asked by
Laura
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Laura
Top achievements
Rank 1
Share this question
or