Drag From GridView Drop On TextBoxCOntrol

3 posts, 0 answers
  1. pierre-jean
    pierre-jean avatar
    99 posts
    Member since:
    Apr 2011

    Posted 10 Nov 2019 Link to this post

    Hello

    I need to perform a drag from a radgridview onto a radtextboxcontrol (which is in a talelayout which is in a PageView control ..)

    I have managed to implement a drag and drop within a gridview to reorder the lines
    and to do a drag from a grid view and drop on another gridview

    but I can't find how to do a drag from a gridview and a drop on the textboxcontrol.
    I guess this is related to the OLEDragandDrop and the RadGradDorpServices but I'm stuck.

    Thanks in advance

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3624 posts

    Posted 12 Nov 2019 Link to this post

    Hello, Pierre-Jean, 

    RadGridView handles the whole drag and drop operation by its RadGridViewDragDropService. The PreviewDragOver event allows you to control on what targets the row being dragged can be dropped on. The PreviewDragDrop event allows you to get a handle on all the aspects of the drag and drop operation, the source (drag) grid, the destination (target) control, as well as the row being dragged. This is where we will initiate the actual physical move of the row(s) from one grid to the target control. 

    I have prepared a sample code snippet for your reference which result is illustrated in the attached gif file: 
            public RadForm1()
            {
                InitializeComponent();
                RadDragDropService svc =
                    this.radGridView1.GridViewElement.GetService<RadDragDropService>();
                svc.PreviewDragStart += svc_PreviewDragStart;
                svc.PreviewDragDrop += svc_PreviewDragDrop;
                svc.PreviewDragOver += svc_PreviewDragOver;
                 
                var gridBehavior = this.radGridView1.GridBehavior as BaseGridBehavior;
                gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
                gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new RowSelectionGridBehavior());
                 
                this.radTextBoxControl1.TextBoxElement.AllowDrop = true; 
            }
    
            //initiates drag and drop service for clicked rows
            public class RowSelectionGridBehavior : GridDataRowBehavior
            {
                protected override bool OnMouseDownLeft(MouseEventArgs e)
                {
                    GridDataRowElement row = this.GetRowAtPoint(e.Location) as GridDataRowElement;
                    if (row != null)
                    {
                        RadGridViewDragDropService svc = this.GridViewElement.GetService<RadGridViewDragDropService>();
                        svc.AllowAutoScrollColumnsWhileDragging = false;
                        svc.AllowAutoScrollRowsWhileDragging = false;
                        svc.Start(row);
                    }
                    return base.OnMouseDownLeft(e);
                }
            }
    
            private void svc_PreviewDragDrop(object sender, RadDropEventArgs e)
            {
                RadTextBoxControlElement dropTextBox = e.HitTarget as RadTextBoxControlElement;
                GridDataRowElement draggedRowElement = e.DragInstance as GridDataRowElement;
                if (dropTextBox == null || draggedRowElement == null)
                {
                    e.Handled = false;
                    return;
                }
                e.Handled = true;
                dropTextBox.Text = draggedRowElement.RowInfo.Cells["ProductName"].Value + "";
            }
    
            private void svc_PreviewDragOver(object sender, RadDragOverEventArgs e)
            {
                e.CanDrop = e.HitTarget is RadTextBoxControlElement;
            }
    
            private void svc_PreviewDragStart(object sender, PreviewDragStartEventArgs e)
            {
                e.CanStart = true;
            }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

     

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. pierre-jean
    pierre-jean avatar
    99 posts
    Member since:
    Apr 2011

    Posted 13 Nov 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello Dess

    thanks a lot it works perfectly.

    The point I was missing is that the drop preview nd the drop occurs on the textboxcontrolelement, I was working on the textboxcontrol itself

    Thanks again

    Pierre-Jean

Back to Top