Enigma04 Enigma04 - 1 year ago 89
Vb.net Question

How to load a file from a combobox

I'm currently have the following code:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim dir = "Path\path\path"
For Each file As String In System.IO.Directory.GetFiles(dir)

End Sub

This code finds a directory and populates a combobox with names of all the files in that directory. I would like to be able to select the file name from the combobox and the file be opened.

Answer Source

Double-click on a combobox, when combobox item changes - launch the file listed in the combobox:

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Dim proc As New System.Diagnostics.Process()
    proc.StartInfo.FileName = ComboBox1.Text
    proc.StartInfo.WorkingDirectory = "Path\path\path"
End Sub
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download