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

Scrolling throws exception on mouse down after dragdrop

1 Answer 13 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Beatrice
Top achievements
Rank 1
Beatrice asked on 24 Nov 2014, 05:52 PM
Hi,

I have 2 radgridview. From gridOCC (source), I dragdrop its id to another grid grdDest (Destination). After dragdropping, I get error when I scroll grdOCC. Nothing has been changed in grdOCC, but still I get error on scrolling. I have the code below (this is underlined below), to exit if the user clicks on the scroll bar. Still it gives error. The code that is bold is where the error kicks out. I have shown the error I am getting all the way below in the post.

Here is the code that throws exception:

Private Sub grdOCC_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles grdOCC.MouseDown
Dim iOCCRowIndex As Integer = 0
Dim iOCCColIndex As Integer = 0

If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.GridHeaderCellElement Then Exit Sub
If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.GridTableHeaderCellElement Then Exit Sub
If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.GridRowHeaderCellElement Then Exit Sub
If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.RadCheckBoxEditorElement Then Exit Sub
If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.GridFilterCellElement Then Exit Sub
If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.GridCheckBoxCellElement Then Exit Sub
If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.RadScrollBarElement Then Exit Sub
If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.ScrollBarThumb Then Exit Sub

If TypeOf (grdOCC.FocusedElement) Is Telerik.WinControls.UI.GridCellElement Then
    Dim gridPointOCC As Point = grdOCC.PointToClient(Windows.Forms.Cursor.Position)
    Dim elm As Telerik.WinControls.UI.GridDataCellElement

    If gridPointOCC.GetType = Nothing Then Exit Sub
    elm = grdOCC.ElementTree.GetElementAtPoint(New Point(gridPointOCC.X, gridPointOCC.Y))
    If elm.RowIndex < 0 Then Exit Sub
    iOCCRowIndex = elm.RowIndex
                
    If iOCCRowIndex >= 0 And elm.ColumnInfo.Name = "ID" Then
        grdOCC.Update()
        iOCCQty = CInt(grdOCC.CurrentRow.Cells("quantity").Value)
        strOCCExch = grdOCC.CurrentRow.Cells("exch_code").Value.ToString
        strOCCSide = grdOCC.CurrentRow.Cells("side").Value.ToString
        strOCCPC = grdOCC.CurrentRow.Cells("pc").Value.ToString
        strOCCSymbol = grdOCC.CurrentRow.Cells("o_sym").Value.ToString
        dblOCCStrike = CDbl(grdOCC.CurrentRow.Cells("strk").Value)

        grdOCC.DoDragDrop(grdOCC.CurrentRow.Cells(1).Value.ToString, DragDropEffects.Copy) 'OCCID
     End If
End If
End Sub

The error I get is:
---------------------------
Grid OCC MouseDown - Fix Exceptions
---------------------------
Unable to cast object of type 'Telerik.WinControls.UI.RadScrollBarElement' to type 'Telerik.WinControls.UI.GridDataCellElement'.
---------------------------
OK  
---------------------------

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 27 Nov 2014, 02:24 PM
Hello Beatrice,

Thank you for writing.

You can properly get the clicked element by using the MouseEventArgs object. Please note that the current row is changed after the mouse is released so it is not suitable to take the value from it:
Private Sub radGridView1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs)
    Dim elm As GridDataCellElement = TryCast(radGridView1.ElementTree.GetElementAtPoint(e.Location), GridDataCellElement)
    If elm IsNot Nothing Then
        radGridView1.DoDragDrop(elm.Value.ToString(), DragDropEffects.Copy)
    End If
End Sub

The grid also has an built-in drag drop service that can be used: Drag and Drop.

Let me know if I can assist you further.
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Beatrice
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or