I have this code modified from example for moving rows between grids:
GridDataRowBehavior:
public
class
RowSelectionGridBehavior : GridDataRowBehavior
{
private
List<GridViewRowInfo> selectedRows =
new
List<GridViewRowInfo>();
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 =
true
;
svc.AllowAutoScrollRowsWhileDragging =
true
;
svc.Start(row);
}
return
base
.OnMouseDownLeft(e);
}
}
My extension of RadGridView
public
delegate
void
MovingItemsEvent(List<GridViewRowInfo> rows,
object
source,
object
target);
public
event
MovingItemsEvent MovingItems;
//THIS IS THE PART I DON'T LIKE
private
void
ExtendedGrid_MouseDown(
object
sender, MouseEventArgs e)
{
if
(e.Button == System.Windows.Forms.MouseButtons.Left && EnableDragnDrop)
{
GridGroupContentCellElement row =
this
.ElementTree.GetElementAtPoint(e.Location)
as
GridGroupContentCellElement;
if
(row !=
null
)
{
RadGridViewDragDropService svc =
this
.GridViewElement.GetService<RadGridViewDragDropService>();
svc.AllowAutoScrollColumnsWhileDragging =
true
;
svc.AllowAutoScrollRowsWhileDragging =
true
;
svc.Start(row);
}
}
}
private
bool
_EnableDragnDrop;
[BrowsableAttribute(
true
)]
public
bool
EnableDragnDrop
{
get
{
return
this
._EnableDragnDrop; }
set
{
_EnableDragnDrop = value;
if
(value)
{
//register the custom row selection behavior
var gridBehavior =
this
.GridBehavior
as
BaseGridBehavior;
gridBehavior.UnregisterBehavior(
typeof
(GridViewDataRowInfo));
//gridBehavior.UnlockBehavior(typeof(GridGroupContentCellElement));
gridBehavior.RegisterBehavior(
typeof
(GridViewDataRowInfo),
new
RowSelectionGridBehavior());
}
}
}
private
void
svc_PreviewDragStart(
object
sender, PreviewDragStartEventArgs e)
{
if
(EnableDragnDrop)
e.CanStart =
true
;
}
private
void
svc_PreviewDragOver(
object
sender, RadDragOverEventArgs e)
{
if
(EnableDragnDrop)
e.CanDrop =
true
;
}
private
void
svc_PreviewDragDrop(
object
sender, RadDropEventArgs e)
{
if
(EnableDragnDrop)
{
var dropTarget = e.HitTarget
as
RadItem;
var targetGrid = dropTarget.ElementTree.Control
as
RadGridView;
//append dragged rows to the end of the target grid
List<GridViewRowInfo> rows =
new
List<GridViewRowInfo>();
if
(e.DragInstance
is
GridGroupContentCellElement)
{
e.Handled =
true
;
GridGroupContentCellElement group = e.DragInstance
as
GridGroupContentCellElement;
foreach
(var row
in
group.ViewInfo.CurrentRow.ChildRows)
{
rows.Add(row);
}
this
.MoveRows(targetGrid, rows);
}
else
if
(e.DragInstance
is
GridDataRowElement)
{
e.Handled =
true
;
foreach
(var row
in
this
.SelectedRows)
{
rows.Add(row);
}
this
.MoveRows(targetGrid, rows);
}
}
}
private
void
MoveRows(RadGridView targetGrid, List<GridViewRowInfo> dragRows)
{
this
.BeginUpdate();
targetGrid.BeginUpdate();
if
(MovingItems !=
null
)
{
MovingItems(dragRows,
this
, targetGrid);
}
this
.EndUpdate(
true
);
targetGrid.EndUpdate(
true
);
}
This works fine without any problem, but I would like if ther is a better way to allow Grouped rows to be dragged, like for example registering a GridBehavior like in the case of ordinary rows