Support Forums

Full Version: Listbox Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am making a password-storage application on Visual Basic (2008). I need to know how, when you add a list item (which I already know how to do), to also specify a password to go with it. Then when you select it on the listbox it displays the password.

Thanks!!
You can use an array to store the passwords and then find the password for the selected item like this: (password() is the array)
Code:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
     msgbox(password(listbox1.selectedindex))  
End Sub
"Password is not declared"...

? I only have intermediate experiance with VB... what is "password"? Should I add a textbox named password or something?
You should add an array named password. You can do that by writing:
Code:
Public password() as string
This code must be added just after Public Class Form1 and not in any sub or event handler because it needs to be accessible by the whole application.
Alright now there are no errors but how does the user specify the password they want to go with each listbox item?

Edit: actually now when I run it and select an item off the list it crashes...
You can add to the window two textboxes and name them (tb_name,tb_password) and then also add a button that says add password.
I the click event of the button add:
Code:
Listbox1.items.add(tb_name.text) 'adds the name to the list box
password.add(tb_password.text) 'adds the password
also you should change the password declaration code to:
Code:
Public password as new list(of String)
Thanks so much! It works now.
Oh wait now I have one problem... I can't use the My.Settings feature to allow users to save it when they open the application next time. How do I do this?
(03-09-2010, 11:02 PM)thanasis2028 Wrote: [ -> ]You can add to the window two textboxes and name them (tb_name,tb_password) and then also add a button that says add password.
I the click event of the button add:
Code:
Listbox1.items.add(tb_name.text) 'adds the name to the list box
password.add(tb_password.text) 'adds the password
also you should change the password declaration code to:
Code:
Public password as new list(of String)

ThanksBlackhat