Hello Howard,
Thank you for writing.
RadGridView handles the whole drag and
drop operation by
RadGridViewDragDropService. The
PreviewDragOver event allows you to control on what targets the item 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) grid, as well as the item being dragged. This is where we will initiate the actual physical move of the dragged item(s) from one grid to the other. In order to implement drag and drop functionality of a column from one grid to another, you can use the
sample approach below:
public
Form1()
{
InitializeComponent();
RadDragDropService svc =
this
.radGridView1.GridViewElement.GetService<RadDragDropService>();
svc.PreviewDragStart += svc_PreviewDragStart;
svc.PreviewDragDrop += svc_PreviewDragDrop;
svc.PreviewDragOver += svc_PreviewDragOver;
}
private
void
svc_PreviewDragStart(
object
sender, PreviewDragStartEventArgs e)
{
e.CanStart =
true
;
}
private
void
svc_PreviewDragOver(
object
sender, RadDragOverEventArgs e)
{
SnapshotDragItem draggedItem = e.DragInstance
as
SnapshotDragItem;
GridHeaderCellElement targetHeaderCell = e.HitTarget
as
GridHeaderCellElement;
if
(draggedItem !=
null
&& targetHeaderCell !=
null
)
{
GridHeaderCellElement sourceHeaderCell = draggedItem.Item
as
GridHeaderCellElement;
if
(sourceHeaderCell !=
null
&& targetHeaderCell.GridViewElement != sourceHeaderCell.GridViewElement)
{
e.CanDrop =
true
;
}
else
{
e.CanDrop =
false
;
}
}
}
private
void
svc_PreviewDragDrop(
object
sender, RadDropEventArgs e)
{
SnapshotDragItem draggedItem = e.DragInstance
as
SnapshotDragItem;
GridHeaderCellElement targetHeaderCell = e.HitTarget
as
GridHeaderCellElement;
if
(draggedItem ==
null
|| targetHeaderCell ==
null
)
{
return
;
}
GridHeaderCellElement sourceHeaderCell = draggedItem.Item
as
GridHeaderCellElement;
if
(sourceHeaderCell !=
null
)
{
e.Handled =
true
;
sourceHeaderCell.GridViewElement.Template.Columns.Remove(sourceHeaderCell.ColumnInfo.Name);
GridViewTemplate targetTemplate = targetHeaderCell.GridViewElement.Template;
targetTemplate.Columns.Insert(targetTemplate.Columns.IndexOf(targetHeaderCell.ColumnInfo.Name),
sourceHeaderCell.ColumnInfo
as
GridViewDataColumn );
}
}
Note that this is just an example and it may not cover all possible cases. Feel free to modify it on a way which suits your requirement best.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik
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 Feedback Portal and vote to affect the priority of the items