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

GetElementAtPoint for DragDropEvent

3 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Technik
Top achievements
Rank 1
Technik asked on 07 May 2008, 01:14 PM
Hi,

I am trying to get the correct row from my grid for the Event RadGridView1.DragDrop.

In http://www.telerik.com/community/forums/thread/b311D-baegte.aspx#410155 you advised to use the GetElementAtPoint method, which is exactly what I need. Has this been removed in Q1_2008 ? Whats the correct way to get a Row by mousecoordinates?

My code looks like this

    Private Sub RadGridView1_DragDrop(ByVal sender As ObjectByVal e As System.Windows.Forms.DragEventArgs) Handles RadGridView1.DragDrop 
        If e.Data.GetDataPresent(GetType(Resource)) Then 
            Dim draggedResource As Resource = CType(e.Data.GetData(GetType(Resource)), Resource) 
            ' GetElementAtPoint does not exist 
            ' Dim target As RadElement = RadGridView1.GetElementAtPoint(New System.Drawing.Point(e.X, e.Y)) 
        End If 
    End Sub 


3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 07 May 2008, 02:32 PM
Hello Falk,

Thank you for getting back to us.

In our latest release of RadControls for WinForms we have redesigned and extended some parts of the Telerik Presentation Framework. The GetElementAtPoint method still exists, but it has been moved to the ElementTree property.

Replace your code with the one below:

Private Sub RadGridView1_DragDrop(ByVal sender As ObjectByVal e As System.Windows.Forms.DragEventArgs) Handles RadGridView1.DragDrop    
    If e.Data.GetDataPresent(GetType(Resource)) Then    
        Dim draggedResource As Resource = CType(e.Data.GetData(GetType(Resource)), Resource)    
        Dim target As RadElement = RadGridView1.ElementTree.GetElementAtPoint(New System.Drawing.Point(e.X, e.Y))    
    End If    
End Sub    
 

I hope this helps. Find more about the changes in our latest release here.

Do not hesitate to write me, if you have other questions.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Technik
Top achievements
Rank 1
answered on 07 May 2008, 02:58 PM
Hello Jack,

thanks for your reply.

I still don't see how I can get the row the item was dropped on.
The ElementTree.GetElementAtPoint returns (in my case) a GridTableBodyElement, which doesn't help me, I think. I need a GridViewDataRowInfo (more precisely, the DataBoundItem of that row).

Can you tell me how to do that?

regards


0
Jack
Telerik team
answered on 07 May 2008, 03:46 PM

Hi Falk,

Thank you for the response.

The GetElementAtPoint method returns the instance of RadElement, which is topmost at the given coordinates. If this is a GridTableBodyElement, then there is no row element at these coordinates. In most cases, the element under the mouse will be a GridCellElement. You can get the GridRowElement that owns this cell by using the RowElement property of the cell.

Consider that the DragDrop event returns screen coordinates. You should convert them to client coordinates for the specified control.

Take a look a the following code snippet:

Private Sub RadGridView1_DragDrop(ByVal sender As ObjectByVal e As System.Windows.Forms.DragEventArgs) Handles RadGridView1.DragDrop    
    If e.Data.GetDataPresent(GetType(Resource)) Then    
        Dim draggedResource As Resource = CType(e.Data.GetData(GetType(Resource)), Resource)    
        Dim point As Point = RadGridView1.PointToClient(New Point(e.X, e.Y))   
        Dim element As RadElement = RadGridView1.ElementTree.GetElementAtPoint(point)   
        Dim cell As GridCellElement = TryCast(element, GridCellElement)   
        Dim row As GridRowElement = Nothing   
        If cell IsNot Nothing Then   
            row = cell.RowElement   
        Else   
            row = TryCast(element, GridRowElement)   
        End If   
    End If    
End Sub   

I hope this helps. Let me know, if you need further assistance.

Greetings,

Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Technik
Top achievements
Rank 1
Answers by
Jack
Telerik team
Technik
Top achievements
Rank 1
Share this question
or