怎么实现文件拖放?
要完成类似foxmail添加附件那样,把文件从一个文件夹拖放到listview中的功能。
不知道触发的是什么事件,我用ListView1_DragEnter试了一下,没有反应?高手指点一二吧?
[解决办法]
Public Class Form1
Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop
Dim strFileNames() As String
Dim strFileName As String
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
strFileNames = e.Data.GetData(DataFormats.FileDrop)
For Each strFileName In strFileNames
Me.ListView1.Items.Add(strFileName)
Next
End If
End Sub
Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
e.Effect = DragDropEffects.All
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ListView1.AllowDrop = True
End Sub
End ClassPublic Class Form1
Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop
Dim strFileNames() As String
Dim strFileName As String
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
strFileNames = e.Data.GetData(DataFormats.FileDrop)
For Each strFileName In strFileNames
Me.ListView1.Items.Add(strFileName)
Next
End If
End Sub
Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
e.Effect = DragDropEffects.All
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ListView1.AllowDrop = True
End Sub
End Class