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

Drag&Drop from RadGridView to RadPanel

1 Answer 83 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Роберт
Top achievements
Rank 1
Роберт asked on 14 Mar 2011, 04:39 PM
Please, see the subject.

Is it possible? Any help, please.

1 Answer, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 17 Mar 2011, 10:37 AM
Hi Vitali Kirakossiants,

Yes, this can be achieved using some standard Windows Forms methods. The following code snippet demonstrates dragging a cell into a RadPanel and displaying it as a RadLabel:
GridDataCellElement hoveredCell = null;
 
public GridDragDrop()
{
    InitializeComponent();
    radPanel1.AllowDrop = true;
 
    radPanel1.DragDrop += new DragEventHandler(radPanel1_DragDrop);
    radPanel1.DragOver += new DragEventHandler(radPanel1_DragOver);
 
    radGridView1.MouseMove += new MouseEventHandler(radGridView1_MouseMove);
}
 
void radPanel1_DragOver(object sender, DragEventArgs e)
{
    e.Effect = e.Data.GetDataPresent(DataFormats.Text) ?
         DragDropEffects.Copy : DragDropEffects.None;
}
 
void radGridView1_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left && hoveredCell!=null)
    {
        radGridView1.DoDragDrop(hoveredCell.Value + "", DragDropEffects.Copy | DragDropEffects.Move);
    }
 
    if (e.Button == System.Windows.Forms.MouseButtons.None)
    {
        GridDataCellElement cellElement = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
        if (cellElement != null)
        {
            hoveredCell = cellElement;
        }
    }
}
 
void radPanel1_DragDrop(object sender, DragEventArgs e)
{
    RadLabel label = new RadLabel();
    label.Location = radPanel1.PointToClient(new Point(e.X, e.Y));
    label.Text = e.Data.GetData(DataFormats.Text).ToString();
    radPanel1.Controls.Add(label);
}

I hope this helps. If you have further questions, feel free to ask.

Greetings,
Ivan Todorov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Роберт
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Share this question
or