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

Grids: Determining where you've dropped

7 Answers 175 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John W Wilson
Top achievements
Rank 1
John W Wilson asked on 15 Jul 2009, 01:07 PM
This has to be simple, but I'm stumped.
I want to drag and drop onto a RadGridView.  I can determine the mouse position of where I have dropped:
    
Dim dropLoc As Point = grdDeliveries.PointToClient(New Point(e.X, e.Y)) 

But I'm stumped as to determine which row this is  as GridDataRowInfo does not give me the row index, or I can't work out how to get it. 

Nor can I work out which part of the row I've dropped on.  (column header, row header, cell, etc.) There is an enumeration 'GridViewHitTestType', but I can't work out how to use it.  HitTest(x,y) just gives true or false.

In other words, what is the equivalent of the Windows DataGridView.HitTestInfo() within the Telerik framework?

7 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 15 Jul 2009, 02:56 PM
Hi John W Wilson,

You can use the ElementTree.GetElementAtPoint method for this purpose. Here is a sample:

Private Sub radGridView1_MouseDown(ByVal sender As ObjectByVal e As MouseEventArgs) 
    Dim cell As GridCellElement = TryCast(Me.radGridView1.ElementTree.GetElementAtPoint(e.Location), GridCellElement) 
    If cell IsNot Nothing Then 
        '... 
    End If 
End Sub 
 

I hope this helps. If you need further assistance, don't hesitate to write us.

 
Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John W Wilson
Top achievements
Rank 1
answered on 15 Jul 2009, 06:37 PM
Thanks Jack,
That works.  I knew it would be simple.  It's just knowing where to look!

John
0
John W Wilson
Top achievements
Rank 1
answered on 16 Jul 2009, 10:03 AM
Actually it didn't work quite as well as I'd hoped.  It gave me the correct return, but never hit the grid as it seemed to give absolute (screen) co-ordinates rather than grid related co-ordinates.  I eventually used
Private Sub grdDeliveries_DragDrop(ByVal sender As ObjectByVal e As System.Windows.Forms.DragEventArgs) Handles grdDeliveries.DragDrop 
.... 
Dim dropLoc As New System.Drawing.Point(e.X, e.Y) 
dropLoc.X = Me.grdDeliveries.MousePosition.X 
dropLoc.Y = Me.grdDeliveries.MousePosition.Y 
...... 


which does work.  However, this gives me the warning
'Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated' 


Any suggestions as to what I've done (am doing) wrong?

0
John W Wilson
Top achievements
Rank 1
answered on 16 Jul 2009, 10:34 AM
And Solved!!

Dim scrpt As New System.Drawing.Point(e.X, e.Y) 
' Check what we are over 
Dim dropLoc As System.Drawing.Point = grdDeliveries.PointToClient(scrpt) 
Dim cell As Telerik.WinControls.UI.GridCellElement = TryCast(grdDeliveries.ElementTree.GetElementAtPoint(dropLoc), Telerik.WinControls.UI.GridCellElement) 
 


I'd missed the .PointToScreen and .PointToClient properties.  The event arguments e come in as screen co-ordinates, which then need to be converted to Client (i.e. grid) co-ordinates.  

0
Accepted
Jack
Telerik team
answered on 16 Jul 2009, 04:39 PM
Hi John,

I am glad to hear that you have found a solution for this issue. If you have any other questions, don't hesitate to write us back.

Feel free to mark this thread as answered.
 

All the best,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Mercell
Top achievements
Rank 2
answered on 17 Feb 2011, 05:15 PM
Hi,

I tried using radGridView.ElementTree.GetElementAtPoint(point)and it works fine when clicking on a textboxcolumn but when clicking on a checkboxcolumn or commandcolumn the returned cell element is null.

I need to determine whether the user doubleclicked a row/cell or outside a cell (but still within the grid).

How do I do this when the grid contains checkboxes or commandbuttons?

Regards,
Brian
0
Jack
Telerik team
answered on 22 Feb 2011, 08:28 AM
Hello Mercell,

I understand. This is because the checkbox itself is an element and the GetElementAtPoint method returns it. You have to check whether some of its parent elements is a GridCellElement. Please consider the following code:
Private Sub radGridView1_MouseDown(sender As Object, e As MouseEventArgs)
    Dim element As RadElement = Me.radGridView1.ElementTree.GetElementAtPoint(e.Location)
    Dim cell As GridCellElement
    While element IsNot Nothing
        cell = TryCast(element, GridCellElement)
        If cell IsNot Nothing Then
            Exit While
        End If
        element = element.Parent
    End While
    ' ...
End Sub

Should you have any further questions, do not hesitate to contact me.
 
Kind regards,
Jack
the Telerik team
Tags
GridView
Asked by
John W Wilson
Top achievements
Rank 1
Answers by
Jack
Telerik team
John W Wilson
Top achievements
Rank 1
Mercell
Top achievements
Rank 2
Share this question
or