使用msflexgrid在两个数据表之间拖放行

时间:2017-07-10 04:13:42

标签: datatable drag msflexgrid

我有两个使用msflexgrid的表单来显示数据来自datatable的数据。

我想在两个表格之间拖放行。我看到了这个主题并进行了编辑,但它没有用。

Drag data from DG and other controls to another DG in vb.net

此错误:

error

请帮助我!

1 个答案:

答案 0 :(得分:0)

这是我的表格1 form1 代码表1:

Imports C1.Win.C1FlexGrid

公共类frm1     私有mdt作为新数据表(“测试”)     私人downHitInfo为C1.Win.C1FlexGrid.HitTestInfo = Nothing

Private Sub frm1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    mdt.Columns.Add("EmplCode")
    mdt.Columns.Add("EmplName")
    mdt.Rows.Add("012345", "A")
    mdt.Rows.Add("012346", "B")
    mdt.Rows.Add("012347", "C")
    flg1.DataSource = mdt
    With flg1
        .DragMode = DragModeEnum.Manual
        .DropMode = DropModeEnum.Manual
    End With
End Sub

Private Sub flg1_MouseDown(sender As Object, e As MouseEventArgs) Handles flg1.MouseDown
    Dim view As C1FlexGrid = CType(sender, C1FlexGrid)
    Dim hitInfo As C1.Win.C1FlexGrid.HitTestInfo = view.HitTest(e.X, e.Y)
    If Not Control.ModifierKeys = Keys.None Then
        Exit Sub
    End If
    If e.Button = MouseButtons.Left Then
        downHitInfo = hitInfo
    End If
End Sub

Private Sub flg1_MouseMove(sender As Object, e As MouseEventArgs) Handles flg1.MouseMove
    Dim view As C1FlexGrid = CType(sender, C1FlexGrid)
    If e.Button = MouseButtons.Left And Not downHitInfo Is Nothing Then
        Dim dragSize As Size = SystemInformation.DragSize
        Dim DragRect As Rectangle = New Rectangle(New Point(Convert.ToInt32(downHitInfo.X - dragSize.Width / 2), _
      Convert.ToInt32(downHitInfo.Y - dragSize.Height / 2)), dragSize)
        If Not DragRect.Contains(New Point(e.X, e.Y)) Then
            'Extract the DataRow
            Dim gridRowView As C1.Win.C1FlexGrid.Row = DirectCast(view.Rows(downHitInfo.Row), C1.Win.C1FlexGrid.Row)
            'Dim rowView As DataRowView = DirectCast(gridRowView.DataBoundItem, DataRowView)
            Dim rowView As DataRowView = DirectCast(gridRowView.DataMap, DataRowView)
            'Raise the DragDrop with the extracted DataRow
            view.DoDragDrop(rowView.Row, DragDropEffects.Move)
            downHitInfo = Nothing
        End If
    End If
End Sub

Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
    Dim lfrm As New frm2()
    lfrm.Show()
End Sub

结束班

这是表格2: Form 2 表格代码2:

Imports C1.Win.C1FlexGrid

公共类frm2     Private Sub frm2_Load(sender as Object,e As EventArgs)处理MyBase.Load         用flg2             .DragMode = DragModeEnum.Manual             .DropMode = DropModeEnum.Manual         结束     结束子

Private Sub flg2_DragOver(sender As Object, e As DragEventArgs) Handles flg2.DragOver
    e.Effect = DragDropEffects.Move
End Sub

Private Sub flg2_DragDrop(sender As Object, e As DragEventArgs) Handles flg2.DragDrop
    Dim draggedRow As DataRow = CType(e.Data.GetData(GetType(DataRow)), DataRow)
End Sub

结束班