Question How to drag and drop multiple files to datagridview?

Speckled

Member
Joined
Feb 12, 2008
Messages
12
Programming Experience
1-3
I have a Windows form with a datagridview on it.

If I select say 5 MP3's and drop them into the datagridview I only get one row appear. How do I handle each file on each drop to add a row?

Here is the code.

VB.NET:
Expand Collapse Copy
Private Sub DataGridView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragEnter
    If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
        e.Effect = DragDropEffects.Copy
    End If

Private Sub DataGridView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DataGridView1.DragDrop
    DataGridView1.Rows.Add((CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString))
End Sub

Thankyou! :)
 
VB.NET:
Expand Collapse Copy
For Each path As String In CType(e.Data.GetData(DataFormats.FileDrop), String())
    DataGridView1.Rows.Add(path)
Next
 
Back
Top