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

Drag and Drop

35 Answers 1020 Views
GridView
This is a migrated thread and some comments may be shown as answers.
New2UI
Top achievements
Rank 1
New2UI asked on 18 May 2007, 03:31 AM
Telerik Team,

Can you drag and drop a row with this control? I am currently using Q1 2007 version.

THanks

35 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 18 May 2007, 01:44 PM
Hi Nemesio,

In its current version RadGridView does not support drag&drop functionality. Can you provide us with more detailed scenario that require such a behavior? We will evaluate all feature requests and will update our ToDo list accordingly. We are planning to provide  drag&drop of rows in one of our next releases.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
dootndo2
Top achievements
Rank 1
answered on 16 Oct 2007, 05:56 AM
I am looking to add rows by dragging and dropping items onto the grid.  Is this possible yet?  I am now on 2007 Q2.  
 
We are trying to allow the user to drag from the RadGridView to a separate control that supports DragDrop.  If they change their mind, they can drag the item from the separate control back to the RadGridView (re-add the row).

Thanks.

Dennis
0
Jack
Telerik team
answered on 16 Oct 2007, 03:38 PM
Hello dootndo2,

Thank you for this question.

The RadGridView doesn't support these drag & drop operations automatically.This feature must be implemented manually.

In order to enable drag & drop operations in the RadGridView you must process certain standard WinForms events. To enable dropping rows to other controls you must attach to MouseDown and MouseMove events and call the DoDragDrop function. To receive dropped rows you must process DragEnter, DragDrop and DragLeave events.

You can find additional information how to implement drag & drop operations on the MSDN site. Follow this link for more information:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dragndropops.asp

We hope this helps you. Don't hesitate to contact us if you have any other questions.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
starlinxy
Top achievements
Rank 1
answered on 02 Jun 2008, 08:25 PM
is there drag and drag supported in the new windows control?  Can you provide an example of how to drag and drop and maintain the focus?
0
Jack
Telerik team
answered on 03 Jun 2008, 07:51 AM
Hi starlinxy,

Thank you for the question.

Drag & drop operations are natively supported by the .Net framework. You should set the AllowDrop property to true and process the events mentioned in the previous post.

Please give me more details on the exact behavior you want to achieve. What do you mean by maintaining the focus? I will be glad to help you further with this issue.

Do not hesitate to contact me if you have other questions.

Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
starlinxy
Top achievements
Rank 1
answered on 03 Jun 2008, 01:00 PM
We want to have 2 data bound gridviews then drag from gridview A to gridview B.  When dragging to gridview B we want the record that the mouse is currently on to be focused so that the user knows where the the item will be dragged and dropped.  After this we would need to know the unique ID of where the focus was on B so we can drop the item and insert into database appropriately.  Here is an example

Grid A contains
ID        FruitNames
----------------------
1            Apple             
2            Orange
3            Kiwi
4            Strawberry

Grid B Contains
ID         FruitNames
----------------------
1        Pear    
2        Watermellon
3        Banana

When the user drags Orange from Grid A over to Grid B and places their mouse cursor on top of Watermellon we want to highlight this Watermellon row immediately.  Then in the back end find the row ID 2 so that we can use that to insert Orange between those 2 items or even replace it appropriately.

We can't find a way to highlite the row appropriately and figure out a way how to get the row selected based on where the mouse is.  If you can setup a simple demo for us that would be great.
0
Jack
Telerik team
answered on 03 Jun 2008, 02:54 PM
Hello starlinxy,

Thank you for getting back to me.

Please find attached a sample project implementing simple drag & drop behavior. You should use the GetElementAtPoint to find the GridRowElement at specific mouse coordinates.

Consider the following code snippet:

GridViewRowInfo GetRowAtPoint(RadGridView grid, Point location) 
    RadElement element = grid.ElementTree.GetElementAtPoint(location); 
    if (element is GridCellElement) 
    { 
        return ((GridCellElement)element).RowInfo; 
    } 
    if (element is GridDataRowElement) 
    { 
        return ((GridRowElement)element).RowInfo; 
    } 
    return null
 

I hope this helps. Please let me know if you have other questions.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Patrick
Top achievements
Rank 1
answered on 01 Jan 2009, 05:36 AM
I have a different question related to drag and drop. I am using Q3 2008. Does the RadGrid support items drag and drop? I would like to manually sort the list by dragging and dropping rows within the same grid (You do support this in the ASP version).

Thanks,

Patrick. 
0
Jack
Telerik team
answered on 05 Jan 2009, 04:19 PM
Hello Patrick,

No, this feature is not supported in RadGridView for WinForms. You could use code similar to the one described in the previous post. We will consider implementing this feature in one of our upcoming releases.

I will be glad helping you further.

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Stargazer
Top achievements
Rank 2
answered on 26 May 2009, 11:12 AM
Hello!

Is there any indication of when will this be available? Seems a lot of folks out there is wanting Drag n' Drop behavior for the RadGridView. Me included! :)

In the meanwhile, I'll have to code the behavior as it was suggested here.
0
Jack
Telerik team
answered on 26 May 2009, 11:25 AM
Hi Stargazer,

I can't give you an exact time frame when it will be implemented. It isn't planned yet. However, we will discus this issue when planning our Q3 release. Of course, if more people request the same functionality we will increase its priority.

Should you have any other questions, don't hesitate to ask.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stargazer
Top achievements
Rank 2
answered on 26 May 2009, 11:26 AM
Well, in fact, what I need to do is moving rows between bound grids... A slightly different achievement from the one on this thread. I'll try to explain.

I have two BindingLists of a custom business object. Then I have two RadGridViews bound to those lists. I want to let the user drag and drop rows from one to the other, affecting the bound lists as the rows get removed or added to each of the RadGridViews. I'm also wanting to use multi selection, so It should let me drag more than one row.

I'm not so sure how I can achieve this one... :S
0
Stargazer
Top achievements
Rank 2
answered on 26 May 2009, 11:49 AM
Hello Jack!

Thanks for the reply. I'll be waiting, then. And hopping that more people ask for this... hehehe

Regards!
0
Mirko
Top achievements
Rank 1
answered on 15 Sep 2009, 09:04 AM
Hello,

Anybody knows how to drag griditem from gridview to the desktop or a windows folder?

Mirko
0
Victor
Telerik team
answered on 17 Sep 2009, 12:07 PM
Hi Mirko,

In order to do this you will have to make use of the native Win32 API since the windows forms drag and drop mechanism does not support un-managed drop targets. Write again if you have other questions.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Niklas
Top achievements
Rank 1
answered on 30 Sep 2009, 12:36 PM
My problem is when I allow MultiSelect the selection changes to the row i clicked.

Same problem described in this post but i am using RadControls for WinForms Q2 2009 SP1.

Any suggestions?
0
Victor
Telerik team
answered on 06 Oct 2009, 07:24 AM
Hi Niklas,

Thank you for your question. In order to get the selected rows before they are cleared, you have to set the grid behavior to a custom one and override OnMouseDown so that you can get the rows before the base logic. For example:
public class MyGridBehavior : BaseGridBehavior 
    private List<GridViewRowInfo> rows = new List<GridViewRowInfo>(); 
    public override bool OnMouseDown(MouseEventArgs e) 
    { 
        this.rows.Clear(); 
        foreach(GridViewRowInfo r in this.GridControl.SelectedRows) 
        { 
            rows.Add(r); 
        } 
        return base.OnMouseDown(e); 
    } 
 
    public List<GridViewRowInfo> SelectedRows 
    { 
        get 
        { 
            return this.rows; 
        } 
    } 

Now you need to create an instance of this behavior, keep a reference to it, and set it to RadGridView like so:
MyGridBehavior behavior = new MyGridBehavior(); 
this.radGridView1.GridBehavior = behavior; 

After this is in place you have to handle MouseDown event of RadGridView and get the selected rows through MyGridBehavior reference.

Write again if you have other questions.

Regards,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mydatafactory
Top achievements
Rank 1
answered on 14 Oct 2009, 07:43 AM
Hello,

I am having the same challenge as Niklas: I want to be able to select multiple rows from a RadGridView and drag and drop them onto a RadTreeView. The code examples with OnMouseDown in combination with the custom GridBehavior works, but is not ideal yet. When you select multiple grid rows and then click again to drag them, it looks like only one row is selected. After you drop them you have to select the other rows again if you want to drag the same rows again somewhere else...

Any suggestions how I can improve this? And I know it has been asked before, but when do you think that drag and drop is fully implemented in the RadGridView? I could really use it :-)

Thanks in advance.

0
Roger Andersson
Top achievements
Rank 1
answered on 15 Oct 2009, 01:41 PM
0
Victor
Telerik team
answered on 19 Oct 2009, 07:05 AM
Hi A. Bennen,

You could easily work around this issue by keeping a collection of the selected rows and setting them to selected again after the drag & drop operation is finished. You can create this temporary collection before you begin the Drag & Drop operation. Please write again if you have other questions.

Best wishes,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nathaniel
Top achievements
Rank 1
answered on 13 Nov 2009, 06:44 PM
I think A. Bennen was referring to the problem that I am encountering. When dragging and dropping on the Telerik GridView with multiple rows selected, the selection is reduced to a single row on MouseDown (unless the CTRL key is pressed). This is very unintuitive behavior. The selection should not be reduced to a single row until MouseUp. Users expects that when they begin to drag, ALL of the selected rows will remain selected until they release the mouse on an acceptable target. It is NOT an acceptable workaround to just reselect the rows after the drag/drop is completed because WHILE the user is dragging it appears that they are only dragging one row.

I found the other thread where it was shown how to create a bitmap of the rows that you are dragging. This is nice, but the original problem remains. I ask outright: why is the row selection reduced to a single row on MouseDown instead of MouseUp? Is this something that can be fixed? We need to have an acceptable fix or workaround or I cannot convince my manager to use the Telerik GridView.

Thank you,
NC
0
Nathaniel
Top achievements
Rank 1
answered on 16 Nov 2009, 11:24 PM
For the benefit of others: Support sent me this code sample, which demonstrates an acceptable workaround.

http://www.telerik.com/ClientsFiles/158846_dragndrop.zip
0
Marcello
Top achievements
Rank 1
answered on 22 Apr 2010, 02:58 PM
Hi,
we are very interested in a native Drag and Drop between grids. Is supported in Q1-2010  version?

Marcello
0
Jack
Telerik team
answered on 23 Apr 2010, 01:43 PM
Hi Nathaniel,

Drag and drop is not supported naively yet. As demonstrated in this thread it could be easily implemented with a few lines of code. Please, tell us whether this solution is suitable for you. If not, describe the exact behavior that you want to achieve and I will be glad to assist you.

We will have in mind the drag & drop feature and we will try to implement it in a future release. Could you please describe what you expect from this feature? We will appreciate your feedback.

 
Kind regards,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
sonu
Top achievements
Rank 1
answered on 30 Aug 2010, 02:54 PM
Hi,

Can u tell me , how can i select multiple grid rows by mouse click..

Thanks
0
Jack
Telerik team
answered on 30 Aug 2010, 09:30 PM
Hello sonu,

Thank you for this question.

First, you have to set the MultiSelect property to true and SelectionMode to FullRowSelect. Here is a sample:

this.radGridView1.MultiSelect = true;
this.radGridView1.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.FullRowSelect;

You have two options when using mouse to select rows:

1.
Keep pressed the Control key and click on the rows that you want  to select.
2. Keep the left mouse button pressed and start dragging over the rows that you want to select.

I hope this helps. If you have any other questions, do not hesitate to contact us.

Sincerely yours, Jack
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
John
Top achievements
Rank 1
answered on 08 Mar 2011, 03:55 PM
Thanks for these samples. I've tried both the files referenced here (087627_GridDragDrop.zip and 158846_dragndrop.zip), and neither of them work with the current framework. The errors are along the lines of:

Error 1 'Telerik.WinControls.UI.GridViewRowInfo' does not contain a definition for 'VisualElement' and no extension method 'VisualElement' accepting a first argument of type 'Telerik.WinControls.UI.GridViewRowInfo' could be found (are you missing a using directive or an assembly reference?) D:\dev\bex2\GridDragDrop\GridDragDrop\Form1.cs 65 41 GridDragDrop

The XAML version mentioned elsewhere in the thread is working, but that's for the XAML GridView rather than the WinForms one. Is there an updated example for the WinForms control? Or is this now a "native" feature of the GridView and I'm just missing the steps to set it in the latest version?
0
Jack
Telerik team
answered on 16 Mar 2011, 05:41 PM
Hi John ,

Both projects represent the same solution. I modified it to be compatible with our latest release, please check the attached project. 

There is an example demonstrating drag & drop between grids in our demo application. It is located under GridView >> Rows >> Rows Drag & Drop.

Should you have any further questions, do not hesitate to ask.

All the best,
Jack
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!
0
John
Top achievements
Rank 1
answered on 13 Apr 2011, 05:59 PM
Thanks for the update. Sorry for the late reply - the notification was in my junk mail folder
0
SRIDHAR
Top achievements
Rank 1
answered on 21 Jun 2013, 05:24 AM
Hi,

    I am having a problem of moving the radgridview in windows...  Is there any property I need to change or else any other solutions for this problem???  

            Thanks in advance.

Thanks & Regards
Sri.
0
Ivan Petrov
Telerik team
answered on 25 Jun 2013, 01:38 PM
Hello Sridhar,

Thank you for writing.

From your explanation I was not able to get a clear idea as of what is wrong and what is not working correctly. I would kindly ask you to send me a more detailed explanation so I will be able to help you.

Looking forward to your reply.

Regards,
Ivan Petrov
Telerik
RadChart for WinForms is obsolete. Now what?
0
Mathieu
Top achievements
Rank 1
answered on 15 May 2014, 07:47 AM
Hi there,

My customer need to drag/drop a row from a RadGridView which contains some files with the fullpath to his windows explorer to get a copy of it. Do you know if it's possible ? Maybe there is an other solution than RadGridView ? 

Thanks in advance.

Regards,
0
Dimitar
Telerik team
answered on 16 May 2014, 01:33 PM
Hello Mathieu,

Thank you for writing.

To achieve the desired behavior you can use the standard drag and drop functionality. For example if you have a column that contains a file path you can copy it to a folder like this:
void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    GridDataCellElement el = radGridView1.GridViewElement.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
 
    if (el != null)
    {
        string path = (string)el.Value;
 
        if (File.Exists(path))
        {
            string[] filesToDrag =
            {
                path
            };
 
            DataObject dob = new DataObject();
            dob.SetData(DataFormats.FileDrop, filesToDrag);
            this.radGridView1.DoDragDrop(dob, DragDropEffects.Copy);
             
        }
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Mathieu
Top achievements
Rank 1
answered on 19 May 2014, 04:23 PM
Hi Dimitar,

Thanks for the reply. Your reply was really helpfull but i'm using it on a different way (playing with MouseDown Location and MouseMove). It's working great.

I just have an issue with the Drag Mouse, it always unselected all the row and keep only the row when i'm starting the drag.

Is there a property to disable the DragMouseSelectRow (?)

Regards,
Mathieu
 



0
Dimitar
Telerik team
answered on 22 May 2014, 09:51 AM
Hello Mathieu,

Thank you for writing back.

If I understand correctly you want the the grid rows to remain selected when you drag and drop them in the explorer. This can be achieved by creating a custom grid behavior. For example:
public class CustomGridBehavior : BaseGridBehavior
{
    List<GridViewRowInfo> selectedRows = new List<GridViewRowInfo>();
 
    public List<GridViewRowInfo> SelectedRows
    {
        get
        {
            return this.selectedRows;
        }
    }
 
    public override bool OnMouseUp(MouseEventArgs e)
    {
        base.OnMouseDown(e);
 
        return base.OnMouseUp(e);
    }
 
    public override bool OnMouseDown(MouseEventArgs e)
    {
        selectedRows.Clear();
 
        selectedRows.AddRange(this.GridControl.SelectedRows);
 
        return true;
    }
}

The behavior can be changed as follows:
radGridView1.GridBehavior = new CustomGridBehavior();

Also you can recreate the MouseDown event in order to copy all the files:  
void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    GridDataCellElement el = radGridView1.GridViewElement.ElementTree.GetElementAtPoint(e.Location) as GridDataCellElement;
 
    if (el != null)
    {
        if (ModifierKeys == Keys.None)
        {
            string[] filesToDrag = new string[radGridView1.SelectedRows.Count];
            for (int i = 0; i < radGridView1.SelectedRows.Count; i ++)
            {
                string path = (string)radGridView1.SelectedRows[i].Cells[0].Value;
                if (File.Exists(path))
                {
                    filesToDrag[i] = path;
                     
                }
            }
                 
            DataObject dob = new DataObject();
            dob.SetData(DataFormats.FileDrop, filesToDrag);
            this.radGridView1.DoDragDrop(dob, DragDropEffects.Copy);
        }
    }
}

I hope this helps.

Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
New2UI
Top achievements
Rank 1
Answers by
Jack
Telerik team
dootndo2
Top achievements
Rank 1
starlinxy
Top achievements
Rank 1
Patrick
Top achievements
Rank 1
Stargazer
Top achievements
Rank 2
Mirko
Top achievements
Rank 1
Victor
Telerik team
Niklas
Top achievements
Rank 1
Mydatafactory
Top achievements
Rank 1
Roger Andersson
Top achievements
Rank 1
Nathaniel
Top achievements
Rank 1
Marcello
Top achievements
Rank 1
sonu
Top achievements
Rank 1
John
Top achievements
Rank 1
SRIDHAR
Top achievements
Rank 1
Ivan Petrov
Telerik team
Mathieu
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or