Drag and drop multirows form a flexgrid to another flexgrid

Originally Posted 6 July 2017, 5:35 am EST

  • Originally Posted 6 July 2017, 5:35 am EST

    Hi all,
    I make two form (form1 and form2) with flexgrid.
    I want to drag and drop form form1's flexgrid to flexgrid of form2's flexgrid
    This is my code in form1, but it don't work:

    Private mblMouseDown As String = String.Empty

    Private Sub frm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim mydt As New Datatable ("MyDatatable")
    mydt.colum.add("Test")
    flg1.datasource = mydt
    flg1.DragMode = DragModeEnum.Manual
    flg1.DropMode = DropModeEnum.Manual
    End Sub


    Private Sub flg1_DragEnter(sender As Object, e As DragEventArgs) Handles flg1.DragEnter
    e.Effect = DragDropEffects.Copy
    End Sub


    Private Sub flg1_MouseDown(sender As Object, e As MouseEventArgs) Handles flg1.MouseDown
    mblMouseDown = True
    End Sub

    Private Sub flg1_MouseLeave(sender As Object, e As EventArgs) Handles flg1.MouseLeave
    If mblMouseDown = True Then
    Dim lstrTemp As String = String.Empty
    lstrTemp = flg1.Rows.Selected().ToString()
    flg1.DoDragDrop(lstrTemp, DragDropEffects.Copy)
    mblMouseDown = False
    End If
    End Sub

    Private Sub flg1_MouseUp(sender As Object, e As MouseEventArgs) Handles flg1.MouseUp
    mblMouseDown = False
    End Sub

    Private Sub frm1_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
    Dim lstrTemp As String = String.Empty
    If e.Data.GetDataPresent(DataFormats.Text) = True Then
    lstrTemp = e.Data.GetData(DataFormats.Text)
    Dim ldrNewrow As DataRow = mydt.NewRow()
    ldrNewrow.Item(0) = lstrTemp
    mydt.Rows.Add(ldrNewrow)
    flgMainCode.DataSource = mydt
    End If
    End Sub
  • Reply

    Hi,

    In order to move multiple rows from first grid to another (being on different forms), you can follow the given steps :

    1. In MouseUp event of first C1FlexGrid, you can check if the user has selected any row (with row header) and then store number of selected rows in a variable.
    Private Sub C1FlexGrid1_MouseUp(sender As Object, e As MouseEventArgs) Handles C1FlexGrid1.MouseUp
    Dim flex As C1FlexGrid = CType(sender, C1FlexGrid)
    Dim hti As HitTestInfo = flex.HitTest(e.X, e.Y)
    If hti.Type = HitTestTypeEnum.RowHeader Then
    mouseUp = True
    'Store number of selected rows
    frm2.rowsMoved = flex.Selection.r2 - flex.Selection.r1 + 1
    rowsMoved = frm2.rowsMoved
    End If
    End Sub


    2. In BeforeMouseDown event of this grid, you can do drag-drop and remove selected rows from this first grid.

    3. Now, in DragOver event of the second C1FlexGrid, you can set target drop effect to DragDropEffects.Move as follows :
    Private Sub C1FlexGrid2_DragOver(sender As Object, e As DragEventArgs) Handles C1FlexGrid2.DragOver
    e.Effect = DragDropEffects.Move
    End Sub


    4. Then, in DragDrop event of the same grid, you can find the drop position and insert the number of rows in the grid. After this, you can select these empty rows and set data in the selected rows.

    Attached is the sample with the same approach. Kindly refer to this for complete implementation. If you have any further query, do let me know.

    Regards,
    Meenakshi
    2017/07/Prj_MoveRowsBetweenGrids1.zip
  • Marked as Answer

    Reply

    Hello Nguyen,

    I have developed a solution and attached it to the post. This allows you to control-click, or shift-click any group of rows in a c1flexgrid and then, you can drag these rows to another bound grid on a separate form.

    Please let me know, if this helps.

    Regards,

    +Manindra
    2017/07/DragToAnotherForm.zip
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels