Results 1 to 3 of 3

Thread: I need help with combo boxes in vb :o please help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    2

    I need help with combo boxes in vb :o please help

    Anything that I write in the textbox, the programme saves it to the drop down list in the combobox but it deletes it once I have closed the programme and opened it again so I tried the following code to ensure that it totally saved it and that it would be available next time I open the programme but it didn't work.....

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Me.ComboBox1.Items.Add(TextBox1.Text)

    For Each comboItem As String In My.Settings.comboboxitems
    Me.ComboBox1.Items.Add(comboItem)
    Next

    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    For Each comboItem As String In My.Settings.comboboxitems
    Me.ComboBox1.Items.Add(comboItem)
    Next
    End Sub
    End Class

    Also, I want to make a programme with a combo box so that when you click an item in the box, it brings up something in a list box.
    Basically, there are different recipes with lists of ingredients, how would I make the recipe name in the combobox display the ingredients in the list box when an item in the combo box is clicked??
    e.g: if there were 3 items in the combo box: fudge cake, waffles and pancakes. If I selected the item "pancakes" then the list box would display something like this...

    eggs, 1
    milk, 200, ml
    water, 10, ml
    flour, 500, grams

    (im pretty sure thats not how to make pancakes but its just an example)

    any help would be greatly appreciated...

    btw, im using vb 2010 and vb express

  2. #2
    Fanatic Member
    Join Date
    Feb 2013
    Posts
    985

    Re: I need help with combo boxes in vb :o please help

    a very simple way would be like this,
    NOTE: this was using a textbox with multiline = true

    make a text file names "whtever recipe" inside it put the ingredients

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    Dim tmpItem As String = ListBox1.SelectedItem.ToString
    Dim tmpPath As String = Windows.Forms.Application.StartupPath & "\" & tmpItem & ".txt"

    If IO.File.Exists(tmpPath) Then
    TextBox1.Text = FileIO.FileSystem.ReadAllText(tmpPath)
    Else
    TextBox1.Text = "No File Found"
    End If
    End Sub

    FileIO.FileSystem.ReadAllText(tmpPath) is perfect for displaying information quickly and easily in a text box
    Yes!!!
    Working from home is so much better than working in an office...
    Nothing can beat the combined stress of getting your work done on time whilst
    1. one toddler keeps pressing your AVR's power button
    2. one baby keeps crying for milk
    3. one child keeps running in and out of the house screaming and shouting
    4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
    5. working at 1 O'clock in the morning because nobody is awake at that time
    6. being grossly underpaid for all your hard work


  3. #3
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: I need help with combo boxes in vb :o please help

    Quote Originally Posted by jazloudan View Post
    Anything that I write in the textbox, the programme saves it to the drop down list in the combobox but it deletes it once I have closed the programme and opened it again so I tried the following code to ensure that it totally saved it and that it would be available next time I open the programme but it didn't work.....

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Me.ComboBox1.Items.Add(TextBox1.Text)

    For Each comboItem As String In My.Settings.comboboxitems
    Me.ComboBox1.Items.Add(comboItem)
    Next

    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    For Each comboItem As String In My.Settings.comboboxitems
    Me.ComboBox1.Items.Add(comboItem)
    Next
    End Sub
    End Class

    Also, I want to make a programme with a combo box so that when you click an item in the box, it brings up something in a list box.
    Basically, there are different recipes with lists of ingredients, how would I make the recipe name in the combobox display the ingredients in the list box when an item in the combo box is clicked??
    e.g: if there were 3 items in the combo box: fudge cake, waffles and pancakes. If I selected the item "pancakes" then the list box would display something like this...

    eggs, 1
    milk, 200, ml
    water, 10, ml
    flour, 500, grams

    (im pretty sure thats not how to make pancakes but its just an example)

    any help would be greatly appreciated...

    btw, im using vb 2010 and vb express
    How well versed are you in programming?

    Your application might be a little more complicated than you think it is. I would suggest using something like an xml file to store your different recipes.

    xml Code:
    1. <Reciepe_Name1>
    2.       <Ingredient1>eggs</Ingredient1>
    3.       <Ingredient2>milk</Ingredient2>
    4.       <Ingredient3>water</Ingredient3>
    5.       <Ingredient4>flour</Ingredient4>
    6.     </Reciepe_Name1>
    7.     <Reciepe_Name2>
    8.       <Ingredient1>eggs</Ingredient1>
    9.       <Ingredient2>milk</Ingredient2>
    10.       <Ingredient3>water</Ingredient3>
    11.       <Ingredient4>flour</Ingredient4>
    12.     </Reciepe_Name2>
    13.      <Reciepe_Name3>
    14.       <Ingredient1>eggs</Ingredient1>
    15.       <Ingredient2>milk</Ingredient2>
    16.       <Ingredient3>water</Ingredient3>
    17.       <Ingredient4>flour</Ingredient4>
    18.     </Reciepe_Name3>

    Using an XML file would making it very easy to read and write recipes from your computer and have them there everytime you open the file

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