drag n drop windows shortcuts with listview, realtime customizing
Im writing a program that i want to have the ability to drag and drop icons(shortcuts included) from the desktop or taskbar into a form listview while having the ability to add, remove, and customize the items in the listview during runtime.
The listview is set up to mimic the look and feel of the windows desktop, large icon and all in a smaller form.
Or is there a better control than listview for this?
Re: drag n drop windows shortcuts with listview, realtime customizing
i guess then the question is how to make this work. i have found multiple solutions for dragndrop on listview, but i cant figure out how to get the icon and shortcut to program on the drop.
the file handling is melting my brain. i thought about making folders in a 'settings' directory and keeping the lnk files there and then just having a sub call up the folder(s) as needed for reading and writing to the listview... no idea, i havent touched vb since version 4.
Re: drag n drop windows shortcuts with listview, realtime customizing
Here is a file that was passed to me a while a back from someone on the forums for extracting icons, add it to your project first. Here is what you're going to want to do after that:
Step 1: Add an image list to the project and go to your listview properties. Set the image list to the one you want. (For this example, we'll say that the listview is lvList and the image list is IM1)
Then modify this code as needed:
vb Code:
Private Sub lvList_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles lvList.DragEnter
'If file drag/drop then
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
'Allow
e.Effect = DragDropEffects.All
End If
End Sub
vb Code:
Private Sub lvList_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles lvList.DragDrop
'Get file path
Dim values() As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
'Load file info from file path
Dim info As New IO.FileInfo(values(0))
'Create a new listview item
Dim item As New ListViewItem
'Create icon extractor
Dim extractor As New IconExtractor
'Extract icon to IM1
'Note that this line is where the extraction of the icon occurs!
Re: drag n drop windows shortcuts with listview, realtime customizing
Oh, here there is one thing I forgot to mention, the iImages that's being used as an image index has to be used outside of the sub. By naming it in the sub, it would then actually reset iImages to 0 every time you ran the sub making the item use the first image every time. Sorry I left that out of my code.
vb Code:
dim iImages as integer = 0
Private Sub lvList_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles lvList.DragDrop