VB.Net - ListBox

Soldato
Joined
21 Jul 2004
Posts
6,360
Location
Harrow, UK
I have written a really basic program:

Code:
Public Class ***

    Private Sub ***_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For Each environment As IO.DirectoryInfo In New IO.DirectoryInfo("S:\Bob\").GetDirectories()
            MainList.Items.Add(environment.Name)
        Next

    End Sub

    Private Sub MainList_Doubleclick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainList.DoubleClick
        MsgBox("lol")
    End Sub
End Class

When I double click on a entry (XYZ) in the list box (MainList), I want to execute a file in:

S:\Bob\XYZ\test\qwerty.123

At the moment, it just outputs a message box saying "lol"

I am not sure how to do this (I am very new to .Net) :(
 
I think this probably should have gone in HG&P? No MS talk in here, please :D

If it was a C# question instead of VB I'd possibly be able to help ;)
 
Code:
[COLOR=black][SIZE=2]System.Diagnostics.Process.Start([/SIZE][SIZE=2][SIZE=2]"filename_in_here"[/SIZE][/SIZE][SIZE=2])[/SIZE][/COLOR]

But come on, a Google would have revealed that in seconds!!
 
Code:
[COLOR=black][SIZE=2]System.Diagnostics.Process.Start([/SIZE][SIZE=2][SIZE=2]"filename_in_here"[/SIZE][/SIZE][SIZE=2])[/SIZE][/COLOR]

But come on, a Google would have revealed that in seconds!!


How do I use the variable that was selected from the ListBox as part of the path to file that is to be executed?
 
How do I use the variable that was selected from the ListBox as part of the path to file that is to be executed?

System.Diagnostics.Process.Start(YourListBoxName.SelectedItem)

EDIT: Not sure why there is a space after the S ...there isn't when I go to edit it :confused:
 
Last edited:
Dim ProgramPath As String
ProgramPath = "C:\Blah Blah\" & YourListBoxName.SelectedItem & "\Blah\Poo.poo"
System.Diagnostics.Process.Start(ProgramPath)

But I'm not sure whether you will be having different programs with different paths if so you will need to tweak the above.
 
Back
Top Bottom