Find Row On Mouse Enter

6 posts, 0 answers
  1. Martin
    Martin avatar
    35 posts
    Member since:
    Jun 2014

    Posted 24 May Link to this post

    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.

     

  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 25 May Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Martin
    Martin avatar
    35 posts
    Member since:
    Jun 2014

    Posted 25 May in reply to Dimitar Link to this post

    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;
                }
            }

  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 25 May Link to this post

    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 Drop 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.
  6. Martin
    Martin avatar
    35 posts
    Member since:
    Jun 2014

    Posted 25 May in reply to Dimitar Link to this post

    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.

  7. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 26 May Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready