I am working on datagrid I have two datagrid I have to copy some value from one datagrid to another using drag and drop. I have write the following code my Drag and Drop event is't firing. Can anyone help me in this regard.
Private Sub DataGridViewCashBook_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridViewCashBook.MouseDown
If e.Button = System.Windows.Forms.MouseButtons.Left Then
Dim Index As Integer
Try
Index = Me.DataGridViewCashBook.HitTest(e.X, e.Y).RowIndex
If Index > -1 Then
'Pass the Index as "Data" argument of the DoDragDrop Function
DataGridViewCashBook.DoDragDrop(DataGridViewCashBook.Rows(Index).Cells(4).Value, DragDropEffects.Move)
'DataGridViewCashBook.Rows.RemoveAt(Index)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Private Sub DataGridViewCashBook_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridViewBankStatment.DragDrop
Try
Dim dr As Decimal
Dim cr As Decimal
Dim nRow As Integer
Dim nCol As Integer
Dim clientPoint As Point
clientPoint = DataGridViewCashBook.PointToClient(New Point(e.X, e.Y))
nRow = DataGridViewCashBook.HitTest(clientPoint.X, clientPoint.Y).RowIndex
nCol = DataGridViewCashBook.HitTest(clientPoint.X, clientPoint.Y).ColumnIndex
Select Case nCol
Case 4
dr = DataGridViewCashBook.Rows(nRow - 1).Cells(nCol).Value
cr = DataGridViewBankStatment.Rows(nRow).Cells(nCol).Value
End Select
DataGridViewBankStatment.Rows.Add()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub