|
-
May 13th, 2013, 12:10 PM
#1
Thread Starter
New Member
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
-
May 13th, 2013, 01:06 PM
#2
Fanatic Member
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

-
May 13th, 2013, 01:56 PM
#3
Addicted Member
Re: I need help with combo boxes in vb :o please help
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|