DRAG DROP DATAGRIDVIEW

M

mcnews

how can i prevent duplicate rows when drag and drop from one datagridview to another?
tia,
mcnewsxp
 
M

mcnews

Private Sub CopySelectedRows()
Dim exists As Boolean = False
For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows
For Each row2 As DataGridViewRow In Me.DataGridView2.Rows
If row.Tag = row2.Tag Then
exists = True
End If
Next
If exists = False Then
Dim rowData(row.Cells.Count - 1) As Object
For i As Integer = 0 To rowData.Length - 1
rowData(i) = row.Cells(i).Value
Next

Me.DataGridView2.Rows.Add(rowData)
Me.DataGridView2.Rows(DataGridView2.RowCount - 2).Tag = row.Tag
End If
Next

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top