Hi,
I am wanting to drop and item onto a RadGridView without having to select the destination grid row first.
Is there a way to detect which row the mouse is hovering over before the drop event occurs?
I find that none of the DragDrop events are firing when the mouse button is released over the destination gridview.
MouseMove does fire, and I was trying to find the RowElement via X and Y Points. Is there a way to do this?
Many Thanks,
Martin.
7 Answers, 1 is accepted
Thank you for writing.
By default, RadGridView uses its own drag drop service. So what is the control that you are dragging from? A complete example is available here: Drag and Drop.
In addition, you can use the GetElementAtPoint method to get the hovered element:
private
void
RadGridView1_MouseMove(
object
sender, MouseEventArgs e)
{
var element = radGridView1.ElementTree.GetElementAtPoint(e.Location);
Console.WriteLine(element);
}
Let me know if I can assist you further.
Regards,
Dimitar
Telerik
Hi Dimitar,
I'm dragging from one grid to another - but the row being dragged is not inserted into the destination grid. On 'drop' the user must confirm (dialog result) before the data is added. It will simply run a LINQ query to update / insert into a SQL table.
I've already got the following code - but I cannot get a row from the element. I need to grab the row data from where the mouse is hovering so I know the ID field, row index and so on:
private
void
dragAndDropGrid2_MouseMove(
object
sender, MouseEventArgs e)
{
RadElement element = dragAndDropGrid2.ElementTree.GetElementAtPoint(
new
Point(e.X, e.Y));
while
(element !=
null
)
{
if
(element
is
GridRowElement)
{
break
;
}
element = element.Parent;
}
}
Thank you for writing back.
You can get the row like this:
private
void
RadGridView1_MouseMove(
object
sender, MouseEventArgs e)
{
var element = radGridView1.ElementTree.GetElementAtPoint(e.Location);
if
(element
is
GridDataCellElement)
{
var row = ((GridDataCellElement)element).RowInfo;
}
}
In addition, I want to say that you can handle this by using the drag-drop service of the first grid only. The
Drag and example shows how this works (take a look at the PreviewDragDrop event handler).
Let me know if you have additional questions.
Regards,
Dimitar
Telerik
Thanks Dimitar,
I was tantalisingly close before, but your solution works a charm.
I can now ensure the row is selected and current using the snippet below:
var row = ((GridDataCellElement)element).RowInfo;
row.IsSelected =
true
;
row.IsCurrent =
true
;
Now that the row is selected and the current selection I can grab any information from any cell and process accordingly.
Many thanks,
Martin.
I am glad I could be of help. Let us know if you have any other questions.
Regards,
Dimitar
Telerik
Hi,
I am trying to achieve something similar, but I have template in my grid. If row is expanded and inner grid is shown, then I drop item into the inner grid, the radGridView1.ElementTree.GetElementAtPoint(e.Location) return null. the GridViewTemplate does not have method ElementTree.
How can I get the row of the main grid if mouse is inside the template?
Hello, Michael,
According to the provided information, I suppose that you are trying to achieve drag and drop operation in a hierarchical RadGridView. Please refer to the attached sample project which result is illustrated in the attached gif file. It shows how to get the target row and move the dragged row to the new parent row.I believe that you will find it useful for achieving your goal.
In case you are still experiencing any further difficulties, I would recommend you to submit a support ticket from your Telerik account and provide a sample project demonstrating the problem you are facing. Thus, the Telerik support engineers would gladly assist you.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.