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

drag drop rows in RadGrid

3 Answers 301 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Susi
Top achievements
Rank 1
Susi asked on 24 Jan 2013, 08:12 AM
Dear All,

I have two RadGridView in WindowsForms namely radGridView1 and radGridView2.
 
I have data in radGridView1 and also i need to drag and drop radGridView1 row to radGridView2 wise single row and multi row.

And also no data in radGridView2.

My coding are mentioned below.

private void Form1_Load(object sender, EventArgs e)
       {
           DataTable dt = new DataTable();
           dt = c.getdata();
           radGridView1.DataSource = dt;
       }
public DataTable getdata()
       {
           con.Open();
           cmd = new SqlCommand("select * from employee", con);
           sda = new SqlDataAdapter(cmd);
           sda.Fill(dt);
 
           con.Close();
           return dt;
       }


How to implement this?

Thanks in Advance..!

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Jan 2013, 10:06 AM
Hi Susi,

There is an example demonstrating drag & drop between grids in winforms demo application. It is located under GridView >> Rows >> Rows Drag & Drop. Following is the sample code with reference to the demo.

C#:
private void dragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
        {
            SnapshotDragItem dragInstance = e.DragInstance as SnapshotDragItem;
 
            if (dragInstance == null)
            {
                return;
            }
 
            RadItem dropTarget = e.HitTarget as RadItem;
            RadGridView targetGrid = dropTarget.ElementTree.Control as RadGridView;
 
            if (targetGrid == null)
            {
                return;
            }
 
            RadGridView dragGrid = dragInstance.Item.ElementTree.Control as RadGridView;
 
            if (targetGrid != dragGrid)
            {
                e.Handled = true;
 
                CustomGridBehavior behavior = (CustomGridBehavior)dragGrid.GridBehavior;
                GridDataRowElement dropTargetRow = dropTarget as GridDataRowElement;
                int index = dropTargetRow != null ? this.GetTargetRowIndex(dropTargetRow, e.DropLocation) : targetGrid.RowCount;
                this.MoveRows(targetGrid, dragGrid, behavior.SelectedRows, index);
            }
        }
 
private void dragDropService_PreviewDragOver(object sender, RadDragOverEventArgs e)
        {
            if (e.DragInstance is SnapshotDragItem)
            {
                e.CanDrop = e.HitTarget is GridDataRowElement || e.HitTarget is GridTableElement || e.HitTarget is GridSummaryRowElement;
            }
        }
 
private void dragDropService_PreviewDragHint(object sender, PreviewDragHintEventArgs e)
        {
            SnapshotDragItem dragInstance = e.DragInstance as SnapshotDragItem;
 
            if (dragInstance == null)
            {
                return;
            }
 
            GridViewRowInfo rowInfo = e.DragInstance.GetDataContext() as GridViewRowInfo;
 
            if (rowInfo != null && rowInfo.ViewTemplate.MasterTemplate.SelectedRows.Count > 1)
            {
                e.DragHint = new Bitmap(this.imageList1.Images[6]);
                e.UseDefaultHint = false;
            }
        }

Hope this helps.

Regards,
Princy.
0
Susi
Top achievements
Rank 1
answered on 24 Jan 2013, 01:14 PM
Thanks for your reply but i am binding Gridview with DataTable from database.I need this kind of bindings to implement this scenario.

Thanks in Advance...!
0
Svett
Telerik team
answered on 25 Jan 2013, 02:12 PM
Hello Sucindran,

Presently, 
RadGridView does not support drag and drop of rows in data bound mode. Nevertheless, you can use a code library that demonstrates how you can customize the control to enable this scenario. You can find it here.

Regards,
Svett
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
GridView
Asked by
Susi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Susi
Top achievements
Rank 1
Svett
Telerik team
Share this question
or