Results 1 to 4 of 4

Thread: [2008] Adding to a listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    2

    [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 !
    Attached Images Attached Images  

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    2

    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:
    1. Dim studentname As String
    2.         studentname = studenttextbox.Text
    3.  
    4.         If studentname = "" Then
    5.             MessageBox.Show("You Need to enter a Name")
    6.         ElseIf studentname Is studentnameslistbox.Text Then
    7.             'how do i make it so the studentname cant already be in the listbox to prevent double up of names.
    8.             MessageBox.Show("Name already in use")
    9.  
    10.         Else
    11.             studentnameslistbox.Items.Add(studenttextbox.Text)
    12.  
    13.         End If
    14.         studenttextbox.Clear()

    i have got the message to appear if the textbox is blank so just need help with the next bit

    cheers

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Adding to a listbox

    ListBox.Items.Contains
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width