2 つのセルの内容とそのマッピングを「交換」しようとしています。これを行うには、文字列値自体ではなく、セルへの参照をドラッグ アンド ドロップする必要があります。次に、この参照を使用して Dictionary を更新し、値を取得できます。そこに必要な値を追加するために古いセルへの参照があるため、スワップを行うことができます。
私が抱えている問題は、セル参照を渡す方法がわからないことです:
Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button = MouseButtons.Left Then
DataGridView1.DoDragDrop(DataGridView1.CurrentCell, DragDropEffects.Copy)
End If
End Sub
そしてドロップイベントで:
Private Sub DataGridView1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
'Problem is here -->'Dim copyedFromCell As DataGridViewCell = DirectCast(e.Data(), DataGridViewCell)**
Dim copyedFromKey As String = GetMappingForCell(copyedFromCell)
Dim thisKey As String = GetMappingForCell(DataGridView1.CurrentCell)
Dim copyedFromValue As String = copyedFromCell.Value
Dim thisValue As String = DataGridView1.CurrentCell.Value
mappings(copyedFromKey) = DataGridView1.CurrentCell
mappings(thisKey) = copyedFromCell
DataGridView1.CurrentCell.Value = copyedFromValue
copyedFromCell.Value = thisValue
End Sub
私がやろうとしていることは可能ですか?私はそれを完全に壊しましたか?ありがとう :)