Jump to content

Help with Listbox!!!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
albeano

albeano

    Newbie

  • Members
  • Pip
  • 3 posts
Hello, i am new to the forums. i Have a question however.

i have a listbox, filled with the list of every single installed program on my computer. what should i code so when i select a program from the listbox and click a button, the program will run. i tried

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        System.Diagnostics.Process.Start("ListBox1.SelectedItems")
    End Sub

and then i tried:

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Shell(ListBox1.SelectedItems)
    End Sub

everytime i run it, it says there is an invalid file destination

what do i Do?!?!?
please and thank you!
but that didnt work. what should i do?


(btw, i am using Microsoft Visual Basic 2010 Express Edition)

#2
Deadlock

Deadlock

    Learning Programmer

  • Members
  • PipPipPip
  • 81 posts
System.Diagnostics.Process.Start(ListBox1.SelectedItems(0))


#3
albeano

albeano

    Newbie

  • Members
  • Pip
  • 3 posts

Deadlock said:

System.Diagnostics.Process.Start(ListBox1.SelectedItems(0))

i tried that and when i debugged it I got an errror saying,

"The system cannot find the file specified"

#4
Deadlock

Deadlock

    Learning Programmer

  • Members
  • PipPipPip
  • 81 posts
Then you have a problem with your programs path. Post the code here because you seem like not having the programs path in the listbox.

#5
albeano

albeano

    Newbie

  • Members
  • Pip
  • 3 posts

Deadlock said:

Then you have a problem with your programs path. Post the code here because you seem like not having the programs path in the listbox.

i dont know if this is what you mean, but this is my full code so far for my form:

Imports Microsoft.Win32
Public Class MainForm2

    Private Sub MainForm2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Key, Reader As RegistryKey, Y As String
        Key = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall", False)
        For Each X In Key.GetSubKeyNames
            Reader = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall\" & X, False)
            If Reader.GetValueNames().Contains("DisplayName") Then
                Y = Reader.GetValue("DisplayName")
                If Not ListBox1.Items.Contains(Y) Then ListBox1.Items.Add(Y)
            End If
        Next
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Str As String = _
TextBox1.Text.Replace("/watch?v=", "/v/")
        AxWindowsMediaPlayer1.URL = Str
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Panel2.Hide()
        Button2.Hide()
        Button3.Show()

    End Sub

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Panel2.Show()
        Button3.Hide()
        Button2.Show()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        System.Diagnostics.Process.Start(ListBox1.SelectedItems(0))
    End Sub
End Class


It is button4 btw with the code you gave me

#6
Deadlock

Deadlock

    Learning Programmer

  • Members
  • PipPipPip
  • 81 posts
Ok. I'm sorry because I don't have time at all. Please post a screenshot for your program just before you click the button (Show me the listbox).

#7
anglina

anglina

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
What does your program do? It reads like it does a few different things. I also don't see any absolute paths to your programs. (If I am understanding what you want correctly)

Are you loading your list with uninstall entries from the registry?

#8
bytelogik

bytelogik

    Newbie

  • Members
  • PipPip
  • 13 posts
albeano,
read the path using System.Diagnostics.Process.Start(ListBox1.SelectedItems(0)) in message box. Check the path for the file.