Drag and Drop

36 posts, 0 answers
  1. SRIDHAR
    SRIDHAR avatar
    2 posts
    Member since:
    Feb 2013

    Posted 21 Jun 2013 Link to this post

    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.
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    717 posts

    Posted 25 Jun 2013 Link to this post

    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?
  3. Mathieu
    Mathieu avatar
    3 posts
    Member since:
    Apr 2012

    Posted 15 May 2014 Link to this post

    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,
  4. Dimitar
    Admin
    Dimitar avatar
    2913 posts

    Posted 16 May 2014 Link to this post

    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.
     
  5. Mathieu
    Mathieu avatar
    3 posts
    Member since:
    Apr 2012

    Posted 19 May 2014 Link to this post

    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
     



  6. Dimitar
    Admin
    Dimitar avatar
    2913 posts

    Posted 22 May 2014 Link to this post

    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.
     
Back to Top