Results 1 to 2 of 2

Thread: [2005] Listview Icons

  1. #1

    Thread Starter
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Post [2005] Listview Icons

    Hello, I am currently using the code below

    Code:
            
    Dim programsdir = Application.StartupPath & "\Programs"
    Dim listprograms = System.IO.Directory.GetFiles(programsdir)
    
    For Each sFile As String In listprograms
    lvPrograms.Items.Add(sFile)
    Next
    To populate my listview control with the shortcuts that in in the "\Programs" folder.

    The problem I'm having is that I want it to extract the icon off of the shortcut and load that into the listview control instead of the file path.

    I have been trying this for hours in a very varied ammount of ways.. can anyone shed me some of their knowledge please??

    Thank you
    -BoKu-

  2. #2
    Lively Member
    Join Date
    Aug 2007
    Posts
    66

    Re: [2005] Listview Icons

    This will get the associated icons from files. You will need to add a imagelist and set the listviews smallimagelist to point to the imagelist.Also set the listview view property to smallicon.
    Code:
       Dim FolderPath As String = "Folder path" 'be sure to include a \ at the end of the folder path
            Dim ExIcon As Icon 'Declare an icon to hold the extracted icon
            'Load the files from folderpath to the listview
            For Each File As String In My.Computer.FileSystem.GetFiles(FolderPath)
            'Only shows the file name you can use substring to remove the extention
                ListView1.Items.Add(My.Computer.FileSystem.GetName(File))
            Next
            'Loop through the list and extract the icon.
            For i As Int32 = 0 To ListView1.Items.Count - 1
                'Extract the icon
                ExIcon = Icon.ExtractAssociatedIcon(FolderPath & ListView1.Items(i).Text)
                'Check to make sure there is an icon
                If ExIcon.ToBitmap IsNot Nothing Then
                    'Add the icon to the imagelist as a bitmap
                    ImageList1.Images.Add(ListView1.Items(i).Text, ExIcon.ToBitmap)
                    'Set the first listviewitems imagekey to point to the icon
                    ListView1.Items(i).ImageKey = ListView1.Items(i).Text
                    'Clear the icon from ExIcon
                    ExIcon = Nothing
                End If
            Next
    This only gets the icon set to the file. If you need the icon from the file a shortcut is pointing to I think I can do that as well.

Posting Permissions

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



Click Here to Expand Forum to Full Width