我有两种带有 msflexgrid 的表单来显示来自数据表的数据源的数据。
我想在两个表单之间拖放行。我看到了这个主题并进行了编辑,但它不起作用。
将数据从 DG 和其他控件拖到 vb.net 中的另一个 DG
这个错误:
请帮我!
我有两种带有 msflexgrid 的表单来显示来自数据表的数据源的数据。
我想在两个表单之间拖放行。我看到了这个主题并进行了编辑,但它不起作用。
将数据从 DG 和其他控件拖到 vb.net 中的另一个 DG
这个错误:
请帮我!
这是我的 form1 form1 代码表 1:
Imports C1.Win.C1FlexGrid
公共类 frm1 Private mdt As New DataTable("Test") Private downHitInfo As 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: 表格 2 表格 2 的代码:
Imports C1.Win.C1FlexGrid
公共类 frm2 Private Sub frm2_Load(sender As Object, e As EventArgs) 使用 flg2 处理 MyBase.Load .DragMode = DragModeEnum.Manual .DropMode = DropModeEnum.Manual End With End Sub
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
结束类