drag and drop doesn't work

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
 
L

Lloyd Sheen

Co said:
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

You have to handle the DragEnter (not always needed) and the DragOver event.
In this event handler all you need to do is the check for FileDrop as a D&D
object as you are doing (If e.Data.GetDataPresent(DataFormats.FileDrop)
Then) and if that object is available then set"

e.Effect=DragDropEffects.Copy (over Move depending on your appication).

Also don't forget to set the return code for the operation so that explorer
will know what happened (your part of the deal).

e.Effect = DragDropEffects.Copy (or None if your handler did nothing).

Since you are getting a file list from explorer I would not suggest using
Move as an effect since I don't know what it would do with the original file
since it would think a move operation took place.

LS
 
C

Co

You have to handle the DragEnter (not always needed) and the DragOver event.
In this event handler all you need to do is the check for FileDrop as a D&D
object as you are doing (If e.Data.GetDataPresent(DataFormats.FileDrop)
Then) and if that object is available then set"

    e.Effect=DragDropEffects.Copy (over Move depending on your appication).

Also don't forget to set the return code for the operation so that explorer
will know what happened (your part of the deal).

    e.Effect = DragDropEffects.Copy (or None if your handler did nothing).

Since you are getting a file list from explorer I would not suggest using
Move as an effect since I don't know what it would do with the original file
since it would think a move operation took place.

LS- Tekst uit oorspronkelijk bericht niet weergeven -

- Tekst uit oorspronkelijk bericht weergeven -

Lloyd,

actually I don't really want to move or copy the files from explorer I
just want to get the credentials from the files.
Like: name, size, ext, location, date created and modified and add
that to my access database.
So the files stay where they are I just add them to my program. It's
kind of a CMS.

any suggestions?

Marco
 

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