1 Attachment(s)
[2008] Adding to a listbox
Hey guys
i am starting to use VB for a uni assignment. this is the first time i have used it.
i am having trouble with it, and cant find tutorials on the net suitable to my version of VB (2008 express)
My first question, one of many
how do i make the list box editible by the user
i want to add to the listbox by adding in a textbox and clicking the 'add student' button.
then able to remove options by selecting them and clicking the 'remove'
when i exit the form and return to the menu form i want the contents of the list box to be avilable from all other forms, so where would this be saved.
i have attached a picture of the form to help you understand.
thanks for the help in advanced.
also if you know of any good tutorials that i could use to save your time.
Thanks !
Re: [2008] Adding to a listbox
1. how do i make the list box editible by the user
Ans: You cannot edit the items in listbox directly. You need to provide a workaround for that.
2. i want to add to the listbox by adding in a textbox and clicking the 'add student' button.
Ans: Listbox1.Items.Add("Hello")
3. able to remove options by selecting them and clicking the 'remove'
Ans: ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
4. when i exit the form and return to the menu form i want the contents of the list box to be avilable from all other forms, so where would this be saved.
Ans: You need to write code to save contents of listbox either to database or to a file on hard-disk.
and yes... welcome to vbforums :)
Re: [2008] Adding to a listbox
all good now, makes alot of sence.
i want to stop a name being being doubled in a listbox. so when i click the add button, it will check if the name from the text box is already in the listbox. if so it will pop up a message 'enter another name'
i am not sure what listbox function to use.
vb Code:
Dim studentname As String
studentname = studenttextbox.Text
If studentname = "" Then
MessageBox.Show("You Need to enter a Name")
ElseIf studentname Is studentnameslistbox.Text Then
'how do i make it so the studentname cant already be in the listbox to prevent double up of names.
MessageBox.Show("Name already in use")
Else
studentnameslistbox.Items.Add(studenttextbox.Text)
End If
studenttextbox.Clear()
i have got the message to appear if the textbox is blank so just need help with the next bit
cheers
Re: [2008] Adding to a listbox