Question:
for people who know how to work with vb "visual basic"?
anonymous
2011-05-31 10:03:49 UTC
so im doing this big project, and im stuck on the "combobox"
so what im trying to do is "on the form i got 2 comboboxes and a picturebox"...

so on the first cbox "combobox" i have these list of things, i click on the first option "ex. nokia" on the cbox and picture of nokia shows up on the picturebox
i have that down..

what im trying to do, is when i click on "nokia" on the first cbox, on the second cbox a list of there models show up "ex. nokia 97, nokia 77 etc.." and a picture would show up of that model

and if i were to change the option from nokia to iphone, the second combobox would have like a list of iphone models

can it be done, and if it can "CAN YOU PLEASE WRITE ME THE CODE" or something, anything would help
ill give you best answer and if yu write something on my other question ill give yu a best answer to that
Three answers:
Jigar D
2011-05-31 10:36:33 UTC
Below code is for VB.NET 2008:



Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

If ComboBox1.Text = "Nokia" Then

Dim items() As Object = {"nokia 77", "nokia 97", "etc"}

ComboBox2.Items.Clear()

ComboBox2.Items.AddRange(items)

ComboBox2.SelectedIndex = 0

End If



If ComboBox1.Text = "Samsung" Then

Dim items() As Object = {"Galaxy Tab", "Galaxy POP", "etc"}

ComboBox2.Items.Clear()

ComboBox2.Items.AddRange(items)

ComboBox2.SelectedIndex = 0

End If

End Sub



Regards,

Jigar.
AJ
2011-05-31 17:20:53 UTC
How are you storing this data? in a dataset? or a List of a class?



bottom line is in the combobox's selection changed event you will have to query against your data and then populate the 2nd combobox



Edit:



The other 2 posters are showing you how to hard code everything. That is not a preferred method as it would require you to rebuild the application every time you make a change. A better way is to create a dynamic application that can grow without having to go back into the code to make changes.



Since this looks to be a small application a textfile would be best to store the types of phones and models.



Then when the application opens, you connect to the textfile by using OLEDBconnection. You can either just load the entire file into a dataset or you can build a class and add them the a List container. I prefer List in that you can use LINQ to query against a group of classes.



In the MSDN help, lookup List, and LINQ.
anonymous
2011-05-31 18:18:27 UTC
Here we go, just stick one combobox on the form, copy and paste it, it'll ask if you want to create a control array, say yes, then insert 1 picture box then double left click on the form, delete everything and paste this across.



Then if you put a little watch thing on every line by double left clicking on it and press the F5 key. You can see how it works, you need to change the path names for the pictures though and at the moment it'll only show pictures for the Nokia phone but I've designed it in such a way you'll have no problem inserting extra models, types of phone and pictures.





Dim x As Integer, y As Integer



Private Sub Combo1_Click(Index As Integer)



Combo1(1).Clear



Call mobiletest(x)

Call modeltest(y)

Call mobilepic(y)



Select Case x



Case 1: Call Nokia

Case 2: Call Erricson



End Select



End Sub



Private Sub Form_Load()



Combo1(0).Text = "Awaiting input"

Combo1(1).Text = "Awaiting input"



Combo1(0).AddItem "Nokia"

Combo1(0).AddItem "Erricson"



End Sub



Public Function Nokia()





Combo1(1).AddItem "Oro"

Combo1(1).AddItem "C5-03"



End Function



Public Function Erricson()



MsgBox ("Awaiting model numbers")

End Function



Public Function mobiletest(x)



If Combo1(0).Text = "Nokia" Then x = 1

If Combo1(0).Text = "Erricson" Then x = 2



End Function



Public Function modeltest(y)



If Combo1(1).Text = "Oro" Then y = 1

If Combo1(1).Text = "C5-03" Then y = 2



End Function



Public Function mobilepic(y)



Select Case y



Case 1: Picture1.picture = LoadPicture("C:\Documents and Settings\user\Desktop\YahooAnswers\Combo\MobilePics\nokia-oro.jpg")

Case 2: Picture1.picture = LoadPicture("C:\Documents and Settings\user\Desktop\YahooAnswers\Combo\MobilePics\nokia-c5-03.jpg")



End Select



End Function


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...