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

Drag From GridView Drop On TextBoxCOntrol

2 Answers 140 Views
GridView
This is a migrated thread and some comments may be shown as answers.
pierre-jean
Top achievements
Rank 1
Veteran
Iron
pierre-jean asked on 10 Nov 2019, 05:24 PM

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 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Nov 2019, 12:21 PM
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.
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 13 Nov 2019, 10:37 AM

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

Tags
GridView
Asked by
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Share this question
or