dthillsr
asked on
Drag and Drop From ListView to ListBox
I am using TreeView to display files in ListView which works fine. I am trying to drag a file from the ListView to a ListBox to do things with the file but I cannot make it work. I do have Allow Drop set to True in the ListBox. Below is the code I have so far.
For the ListView
Private Sub lstDirectoryInfo_ItemDrag( sender As Object, e As ItemDragEventArgs) Handles lstDirectoryInfo.ItemDrag
Dim lvItem As ListViewItem
lvItem = CType(e.Item, ListViewItem)
Dim importantData As String
importantData = lvItem.Text
Dim drp As DragDropEffects
drp = lstDirectoryInfo.DoDragDro p(e.Item, DragDropEffects.Copy)
MessageBox.Show(drp.ToStri ng())
End Sub
For The ListBox
Private Sub lstSFTP_DragDrop(sender As Object, e As DragEventArgs) Handles lstSFTP.DragDrop
Dim str As String = CStr(e.Data.GetData(DataFo rmats.Stri ngFormat))
lstSFTP.Items.Add(str)
End Sub
Private Sub lstSFTP_DragEnter(sender As Object, e As DragEventArgs) Handles lstSFTP.DragEnter
If (e.Data.GetDataPresent(Dat aFormats.F ileDrop)) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
What I want to accomplish is have the filename in the ListBox.
Thank You
For the ListView
Private Sub lstDirectoryInfo_ItemDrag(
Dim lvItem As ListViewItem
lvItem = CType(e.Item, ListViewItem)
Dim importantData As String
importantData = lvItem.Text
Dim drp As DragDropEffects
drp = lstDirectoryInfo.DoDragDro
MessageBox.Show(drp.ToStri
End Sub
For The ListBox
Private Sub lstSFTP_DragDrop(sender As Object, e As DragEventArgs) Handles lstSFTP.DragDrop
Dim str As String = CStr(e.Data.GetData(DataFo
lstSFTP.Items.Add(str)
End Sub
Private Sub lstSFTP_DragEnter(sender As Object, e As DragEventArgs) Handles lstSFTP.DragEnter
If (e.Data.GetDataPresent(Dat
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
What I want to accomplish is have the filename in the ListBox.
Thank You
ASKER
That did not help. I need to mention also that when I click on an item in the listbox I get a circle with a line through it for the cursor I have enclosed a document with a print screen of that.
Drag-Error.docx
Drag-Error.docx
I think the issue is in your dragenter event. You are only allowing a drop if the item being dragged is a file which it isn't.
ASKER
Would you know how I would adjust the code?
ASKER
I have figured this out and no longer need assistance.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for dthillsr's comment #a40687755
for the following reason:
I did more research on listview in order to correct the problem.
Accepted answer: 0 points for dthillsr's comment #a40687755
for the following reason:
I did more research on listview in order to correct the problem.
and your solution was? please do not enclose graphics in a word document in the future
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
drp = lstDirectoryInfo.DoDragDro
try this:
lstDirectoryInfo.DoDragDro