Click here to Skip to main content
16,016,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
To start off im new to VB and I m trying to create an application launcher that pulls the items i want to launch from a folder.I can get the items to load with the icon, the only are im having is turning the selected item in a list view box to string so i can use it a a variable in the rest of my code.

here is the code i have so far, Help would be great. my main goal is to make it so when i double click an item it will open what ever that item is. ie a vbs script or a text file.

VB
Imports System.IO

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Dir As New DirectoryInfo("C:\Program Files (x86)\AutoHotkey")
        FillListView(Dir)
    End Sub

    Private Sub FillListView(ByVal Folder As DirectoryInfo)
        Static ImageList As New ImageList With {.ColorDepth = ColorDepth.Depth32Bit, .ImageSize = New Size(22, 22)}
        Static ImgIndex As Integer = 0

        ListView1.LargeImageList = ImageList
        ListView1.View = View.Tile

        For Each F As FileInfo In Folder.GetFiles("*.exe")
            ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
            ListView1.Items.Add(F.Name, ImgIndex).Tag = F
            ImgIndex += 1
        Next

        For Each F As FileInfo In Folder.GetFiles("*.txt")
            ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
            ListView1.Items.Add(F.Name, ImgIndex).Tag = F
            ImgIndex += 1
        Next

        For Each F As FileInfo In Folder.GetFiles("*.hta")
            ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
            ListView1.Items.Add(F.Name, ImgIndex).Tag = F
            ImgIndex += 1
        Next

        For Each F As FileInfo In Folder.GetFiles("*.vbs")
            ImageList.Images.Add(Drawing.Icon.ExtractAssociatedIcon(F.FullName))
            ListView1.Items.Add(F.Name, ImgIndex).Tag = F
            ImgIndex += 1
        Next

        For Each Dir As DirectoryInfo In Folder.GetDirectories
            FillListView(Dir)
        Next
    End Sub


End Class
Posted
Updated 1-Feb-12 17:00pm
v2
Comments
manognya kota 1-Feb-12 23:00pm    
Added <pre> tag.
manognya kota 1-Feb-12 23:43pm    
Where is the code that you tried for getting selected listitem?

1 solution

try this:

VB
fname= Listview1.SelectedItems(0).Text
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900