Results 1 to 7 of 7

Thread: drag n drop windows shortcuts with listview, realtime customizing

  1. #1
    New Member
    Join Date
    Aug 12
    Posts
    8

    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?

    thanks in advance

    --
    Go to the source

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,555

    Re: drag n drop windows shortcuts with listview, realtime customizing

    If that's the question I'm not sure that there's any other control let alone a better one.

  3. #3
    New Member
    Join Date
    Aug 12
    Posts
    8

    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.

  4. #4
    Addicted Member EilaDoll's Avatar
    Join Date
    Dec 11
    Posts
    144

    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:
    1. Private Sub lvList_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles lvList.DragEnter
    2.         'If file drag/drop then
    3.         If e.Data.GetDataPresent(DataFormats.FileDrop) Then
    4.  
    5.             'Allow
    6.             e.Effect = DragDropEffects.All
    7.         End If
    8.     End Sub

    vb Code:
    1. Private Sub lvList_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles lvList.DragDrop
    2.             'Get file path
    3.             Dim values() As String = DirectCast(e.Data.GetData(DataFormats.FileDrop), String())
    4.  
    5.             'Load file info from file path
    6.             Dim info As New IO.FileInfo(values(0))
    7.  
    8.             'Create a new listview item
    9.             Dim item As New ListViewItem
    10.  
    11.             'Create icon extractor
    12.             Dim extractor As New IconExtractor
    13.  
    14.             'Extract icon to IM1
    15.             'Note that this line is where the extraction of the icon occurs!
    16.             IM1.Images.Add(extractor.Extract(info.FullName, IconSize.Large))
    17.  
    18.             'Set item text to file name without extension
    19.             item.Text = IO.Path.GetFileNameWithoutExtension(info.FullName)
    20.  
    21.             'Set item image index
    22.             item.ImageIndex = iImages
    23.  
    24.             'Set item tag to file path
    25.             item.Tag = info.FullName
    26.  
    27.             'Add item to list view
    28.             lvList.Items.Add(item)
    29.  
    30.             'Incriment image index
    31.             iImages += 1
    32. End Sub
    Attached Files Attached Files
    Last edited by EilaDoll; Aug 15th, 2012 at 06:27 PM.
    http://www.vbforums.com/image.php?type=sigpic&userid=142423&dateline=1337150730

  5. #5
    New Member
    Join Date
    Aug 12
    Posts
    8

    Re: drag n drop windows shortcuts with listview, realtime customizing

    works very well, but it seems to be loading the same icon for each different item dropped.

  6. #6
    Addicted Member EilaDoll's Avatar
    Join Date
    Dec 11
    Posts
    144

    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:
    1. dim iImages as integer = 0
    2.  
    3. Private Sub lvList_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles lvList.DragDrop
    4. 'code from earlier
    5. End Sub
    http://www.vbforums.com/image.php?type=sigpic&userid=142423&dateline=1337150730

  7. #7
    New Member
    Join Date
    Aug 12
    Posts
    8

    Re: drag n drop windows shortcuts with listview, realtime customizing

    sweet, thanks so much, it works great, now on to writing/reading settings in xml.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •