This is a migrated thread and some comments may be shown as answers.

Find Row On Mouse Enter

7 Answers 603 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 24 May 2016, 04:09 PM

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

Sort by
0
Dimitar
Telerik team
answered on 25 May 2016, 09:40 AM
Hi Martin,

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
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Martin
Top achievements
Rank 1
answered on 25 May 2016, 10:02 AM

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)
                {
                                                         //Need to set row to element here
                    break;
                }
                element = element.Parent;
            }
        }

0
Dimitar
Telerik team
answered on 25 May 2016, 01:05 PM
Hello Martin,

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
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Martin
Top achievements
Rank 1
answered on 25 May 2016, 01:19 PM

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.

0
Dimitar
Telerik team
answered on 26 May 2016, 06:57 AM
Hello Martin,

I am glad I could be of help. Let us know if you have any other questions.

Regards,
Dimitar
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Michael
Top achievements
Rank 1
answered on 31 Aug 2020, 07:47 PM

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? 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Sep 2020, 06:39 AM

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/.

Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Martin
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or