We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Drag&Drop with custom MouseController

I have to drag&drop entire rows inside a grid. We do NOT use row and column headers for other reasons.

So I've found a solution here with a custom mouse controller:

http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=61704

That work's pretty fine so far. Regardless of the clicked column, I'm always selecting the entire row with the red frame.

An important fact in our grid is:

Not every row is allowed for dropping. Only a certain number of rows inside the grid are targets. Outside this range, dropping is not allowed.

In my custom mouse controller in the MouseMove-Eventhandler, I'm taking care of that. The red dragging selection can not go beyond an upper an lower row.

That works fine for the red frame. But when the mouse goes beyond this borders, the old gray/dotted dragging selection becomes visible. And this looks not good for the user.

Is it possible to definitively suppress the old (default) dragging selection frame?

Regards
Andreas


2 Replies

HA haneefm Syncfusion Team February 8, 2008 07:03 PM UTC

Hi AndreasG,

Bydefault , GridControl calls the OutlineDropTargetRange method of GridOleDropTarget class to color the OleDropTarget rectangle. If you want to change the color of the OleDropRectangle, you need to derive GridOleDropTarget class and override the OutlineDropTargetRange method. Blow are the codes that shows this task.

public class MyGrid : GridControl
{
public MyGrid()
: base()
{
}
protected override GridOleDropTarget CreateOleDropTarget(GridControlBase grid, int flags)
{
MyGridOleDropTaget target = new MyGridOleDropTaget(grid);
target.Register(flags);
return target;
}
}

public class MyGridOleDropTaget : GridOleDropTarget
{
public MyGridOleDropTaget(GridControlBase grid)
: base(grid)
{

}
protected override void OutlineDropTargetRange(Point point, bool bEraseOld, bool bDrawNew)
{
int row,col;
if (this.Grid.PointToRowCol(point, out row, out col))
{
using (Graphics g = this.Grid.CreateGridGraphics())
{
int rowOffset = this.Grid.Model.DragDropData.dndRowOffset;
int colOffset = this.Grid.Model.DragDropData.dndColOffset;
Rectangle bounds = this.Grid.RangeInfoToRectangle(GridRangeInfo.Cells(row, col, row + rowOffset, col + this.Grid.Model.DragDropData.dndColOffset));
g.DrawRectangle(new Pen(Color.Red, 3f), bounds);
}
}
}
}

Best regards,
Haneef



AG Andreas Gfeller February 13, 2008 03:11 PM UTC

Thank you Haneef, this is EXACTLY the code I was looking for!

Andreas


Loader.
Live Chat Icon For mobile
Up arrow icon