C
Co
Hi All,
I have a Listview on an Explorer form and I'm trying to add files from
Windows Explorer into the Listview.
I set the Listview drag and drop = True but with the code I found it
doesn't happen:
Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim MyFiles() As String
Dim i As Integer
' Assign the files to an array.
MyFiles = e.Data.GetData(DataFormats.FileDrop)
' Loop through the array and add the files to the list.
For i = 0 To MyFiles.Length - 1
Dim lvitem As New ListViewItem
lvitem.Text =
System.IO.Path.GetFileNameWithoutExtension(MyFiles(i)) 'File Name e.g.
"Notepad"
lvitem.SubItems.Add(My.Computer.FileSystem.GetFileInfo
(MyFiles(i)).Extension) 'Just the extension e.g. ".exe", soon to be
type e.g. "Application"
lvitem.SubItems.Add
(((My.Computer.FileSystem.GetFileInfo(MyFiles(i)).Length) / 1000) & "
KB") 'File Size e.g. "2,400KB"
lvitem.SubItems.Add(My.Computer.FileSystem.GetFileInfo
(MyFiles(i)).DirectoryName) 'Path of file e.g. "C:\Temp"
ListView.Items.Add(lvitem)
Next
End If
End Sub
When I move over the Listview with 1 or more files selected I get the
circle with the line through indicating
that I can't drop.
Marco
I have a Listview on an Explorer form and I'm trying to add files from
Windows Explorer into the Listview.
I set the Listview drag and drop = True but with the code I found it
doesn't happen:
Private Sub ListView_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView.DragDrop
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim MyFiles() As String
Dim i As Integer
' Assign the files to an array.
MyFiles = e.Data.GetData(DataFormats.FileDrop)
' Loop through the array and add the files to the list.
For i = 0 To MyFiles.Length - 1
Dim lvitem As New ListViewItem
lvitem.Text =
System.IO.Path.GetFileNameWithoutExtension(MyFiles(i)) 'File Name e.g.
"Notepad"
lvitem.SubItems.Add(My.Computer.FileSystem.GetFileInfo
(MyFiles(i)).Extension) 'Just the extension e.g. ".exe", soon to be
type e.g. "Application"
lvitem.SubItems.Add
(((My.Computer.FileSystem.GetFileInfo(MyFiles(i)).Length) / 1000) & "
KB") 'File Size e.g. "2,400KB"
lvitem.SubItems.Add(My.Computer.FileSystem.GetFileInfo
(MyFiles(i)).DirectoryName) 'Path of file e.g. "C:\Temp"
ListView.Items.Add(lvitem)
Next
End If
End Sub
When I move over the Listview with 1 or more files selected I get the
circle with the line through indicating
that I can't drop.
Marco