0
當我檢查複選框並嘗試拖放時,我遇到了延遲問題。當我選擇一個複選框並嘗試移動它時,它不會移動。如果我點擊該複選框並點擊不同的行,然後嘗試移動它將起作用。它的工作原理是一樣的,無論我檢查多少,如果不先點擊其他地方,它不會得到最新的一行。我是否需要添加另一個事件來處理或提取該框現在已被檢查?延遲撿起單擊事件
Private Sub datagridview_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagridview.MouseDown
mouseDownPosition = e.Location
End Sub
Private Sub datagridview_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagridview.MouseMove
If CheckMouseMovement(sender, datagridview, e) Then
listofBuilds = New List(Of Build)
For Each row As DataGridViewRow In dataGridView.Rows
If Convert.ToBoolean(row.Cells.Item(0).Value) Then
Dim t As Build = DirectCast(row.DataBoundItem, Build)
listofBuilds.Add(t)
End If
Next
If listofBuilds.Count > 0 Then
dataGridView.EndEdit()
dataGridView.DoDragDrop(sender, dropEffect)
End If
End If
End Sub
Private Sub TabControl_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TabControl.DragEnter
e.Effect = DragDropEffects.All
End Sub
Private Sub TabControl_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TabControl.DragDrop
Dim DropPage As TabPage = GetTabPageByTab(TabControl.PointToClient(New Point(e.X, e.Y)))
If DropPage IsNot TabControl.SelectedTab Then
If DropPage Is Page1 Then
If DropPage Is Page2 Then
If DropPage Is Page3 Then
//etc
End If
End If
End Sub
Private Function GetTabPageByTab(ByVal point As Point) As TabPage
For i As Integer = 0 To TabControl.TabPages.Count - 1
If TabControl.GetTabRect(i).Contains(point) Then
Return TabControl.TabPages.Item(i)
End If
Next
Return Nothing
End Function
嘗試在['datagridview.EndEdit()'](https://msdn.microsoft.com/en-us/library/ms158620%28v=vs.110%29.aspx)開頭添加一個調用'datagridview_MouseMove'方法。 – Mark
不確定延遲是指什麼,但嘗試將網格的EditMode屬性設置爲EditOnEnter。 – LarsTech
@Mark謝謝你的工作。你可以把它作爲答案,我可以接受它。 –