Scrolling throws exception on mouse down after dragdrop

2 posts, 1 answers
  1. Beatrice
    Beatrice avatar
    10 posts
    Member since:
    Jun 2014

    Posted 24 Nov 2014 Link to this post

    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  
    ---------------------------
  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2686 posts

    Posted 27 Nov 2014 Link to this post

    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.

     
Back to Top