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
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
Re: I need help with combo boxes in vb :o please help
Quote:
Originally Posted by
jazloudan
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:
<Reciepe_Name1>
<Ingredient1>eggs</Ingredient1>
<Ingredient2>milk</Ingredient2>
<Ingredient3>water</Ingredient3>
<Ingredient4>flour</Ingredient4>
</Reciepe_Name1>
<Reciepe_Name2>
<Ingredient1>eggs</Ingredient1>
<Ingredient2>milk</Ingredient2>
<Ingredient3>water</Ingredient3>
<Ingredient4>flour</Ingredient4>
</Reciepe_Name2>
<Reciepe_Name3>
<Ingredient1>eggs</Ingredient1>
<Ingredient2>milk</Ingredient2>
<Ingredient3>water</Ingredient3>
<Ingredient4>flour</Ingredient4>
</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