For example, I have 4 grids in a docking panel. lets call them grids1 - grid4. grid1 and grid2 has values I want to share with grid2. grids 3 and grid4 do not except any drop. However, what is happening is that when I drag from grid1 to grid4 it addes the value to grid2. How can I tell if the grid I am hovering over is the grid that I want to add the value to.
Thanks
Stephen
9 Answers, 1 is accepted
I am afraid that I have not enough information about how exactly you have tried to implement Drag And Drop scenario. Determining on which grid you are dropping the dragged row is specific for the chosen implementation. If you are using MouseUp event to finnish dropping, you can check which RadGridView contains the cursor. For example:
private
void
rgvDrag_MouseUp(
object
sender, MouseEventArgs e)
{
var screenPoint = rgvDrag.PointToScreen(e.Location);
var point = PointToClient(screenPoint );
if
(radGridView2.Bounds.Contains(point))
{
//....
}
else
if
(radGridView3.Bounds.Contains(point))
{
//....
}
}
If this does not match your scenario, please open a new support ticket and send us a small example project that demonstrates your case. This will help us to investigate the problem further and provide more accurate assistance.
Kind regards,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
(radGridView2.Bounds.Contains(point)) says, if the mouse points to grid 2 then execute code. The problem I have is that the bounds of both grids are x=0 y=0 because they are in a split container. Is there a another way to get the postion of the grid in the parent container?
When using MouseUp event - as in the sample - you will get coordinates relative to the grid that started the drag/drop operation. First you have to convert these coordinates to screen coordinates just like in the sample. You should convert also the location of your grids in screen coordinates. Here is a sample:
Rectangle bounds =
new
Rectangle(
this
.radGridView2.PointToScreen(
new
Point(0, 0)),
this
.radGridView2.Size);
Using screen coordinates it will be easy to determine which grid contains the point:
void
rgvDrag_MouseUp(
object
sender, MouseEventArgs e)
{
Point screenPoint = rgvDrag.PointToScreen(e.Location);
foreach
(RadGridView grid
in
myGrids)
{
Point location = grid.PointToScreen(
new
Point(0, 0));
Rectangle bounds =
new
Rectangle(location, grid.Size);
if
(bounds.Contains(screenPoint))
{
DoDragDropOperation();
return
;
}
}
}
If you need further assistance, just ask.
Sincerely yours,Jack
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
foreach
(RadGridView grid
in
myGrids)
I tried using this.Controls.OfType<MyGrid> (MyGrid is a inherited radgridview I use for the grids) but it keeps coming back null. What to you interrate though to get all of the grids?
List<MyCustomGrid> myGrids = new List<MyCustomGrid>(); |
myGrids.AddRange(splitPanel1.Controls.OfType<MyCustomGrid>()); |
myGrids.AddRange(splitPanel2.Controls.OfType<MyCustomGrid>()); |
foreach (MyCustomGrid gv in myGrids) |
{ |
// do stuff |
} |
Yes, Robert that was it. Thanks. However, after the first drag and drop I either get a null refernce for the outlineForm (used to create image to the dragged item) or the mouse up pulls the first line of the grid instead of the one I am selecting.
In the mouse up I clear the outlineform (= null) to get ride of the bitmat. When go to drag a row from another grid, goes back into the movemouse method and the app thinks I am dragging when I am not. I cannot figure out where to tell the app I am done dragging and ready to start a new drag.
any suggestions?
private void GridViewMouseMove(MyCustomGrid fromGrid, MouseEventArgs e) |
{ |
if (e.Button == MouseButtons.Left) |
{ |
if (!dragging && IsRealDrag(e.Location, downPt)) |
{ |
RadElement element = fromGrid.ElementTree.GetElementAtPoint(e.Location); |
GridDataCellElement cell = element as GridDataCellElement; |
if (cell != null && cell.RowElement is GridDataRowElement) |
{ |
dragging = true; |
fromGrid.Capture = true; |
fromGrid.Cursor = Cursors.Hand; |
Bitmap itemBitmap = GetBitmap(fromGrid); |
outlineForm = TelerikHelper.CreateOutlineForm(itemBitmap); |
outlineForm.MinimumSize = itemBitmap.Size; |
outlineForm.Size = itemBitmap.Size; |
Point mousePt = Cursor.Position; |
outlineForm.Location = new Point(mousePt.X + 5, mousePt.Y + 5); |
outlineForm.TopMost = true; |
outlineForm.Show(); |
} |
} |
else if (dragging) |
{ |
Point mousePt = Control.MousePosition; |
outlineForm.Location = new Point(mousePt.X + 5, mousePt.Y + 5); |
} |
} |
} |
private void GridViewMouseUp(MyCustomGrid fromGrid, MouseEventArgs e) |
{ |
if (dragging) |
{ |
if (outlineForm != null && downPt.Equals(e.Location)) |
{ |
outlineForm.Close(); |
outlineForm.Dispose(); |
outlineForm = null; |
} |
Point screenPoint = fromGrid.PointToScreen(e.Location); |
List<MyCustomGrid> myGrids = new List<MyCustomGrid>(); |
myGrids.AddRange(splitPanel3.Controls.OfType<MyCustomGrid>()); |
myGrids.AddRange(splitPanel4.Controls.OfType<MyCustomGrid>()); |
foreach (MyCustomGrid grid in myGrids) |
{ |
Point location = grid.PointToScreen(new Point(0, 0)); |
Rectangle bounds = new Rectangle(location, grid.Size); |
if (bounds.Contains(screenPoint)) |
{ |
foreach (GridViewDataRowInfo row in fromGrid.RowsToDragDrop) |
{ |
ToRadGridView.Rows.Add(row.Cells[0].Value, row.Cells[1].Value, row.Cells[2].Value); |
fromGrid.Rows.Remove(row); |
} |
return; |
} |
} |
fromGrid.Cursor = Cursors.Arrow; |
fromGrid.Capture = false; |
dragging = false; |
} |
} |
I checked your code. It differs a bit from the code in this forum thread. In your GridViewMouseUp method there is a return which skips the code at the end of the method. This code is important because it resets the dragging operation by setting the dragging variable to false. You should replace this return with a break statement. Should you have any further questions, please write me back.
All the best,
Jack
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.