943,677 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 583
  • VB.NET RSS
Feb 24th, 2009
0

Combo Box Help

Expand Post »
Hi,
i wanted to link options selected from Comb box A (general) to specific options in combo box B (specific). I want to pick a word in Combo box A that has specific words/phrases in Combo Box B show. But not all the words to show in the combo box B if they aren't associated with the Word picked in Combo Box A. Ex.When "Soda" is picked in A, only "Coke, Sprite, Fanta" should be visible in combo box b, not everything else.

This is the code i used to make the boxes, but i don't know how to link them.

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' fills the combo boxes with values

Me.xGeneralComboBox.Items.Add("Soda")
Me.xGeneralComboBox.Items.Add("Juice")

Me.xxSpecificComboBox.Items.Add("Coke")
Me.xxSpecificComboBox.Items.Add("Sprite")
Me.xxSpecificComboBox.Items.Add("Fanta")

Me.xxSpecificComboBox.Items.Add("Apple")
Me.xxSpecificComboBox.Items.Add("Grape")
Me.xxSpecificComboBox.Items.Add("Pear")
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Feb 24th, 2009
0

Re: Combo Box Help

Couldn't you use:

Pseudocode:

if generalcomobobox is soda then
comboboxspecific items = sprite, etc.
elseif generalcombobox is Juice then
comboboxspecific items = apple, etc.


you could do this in generalcombo box's SelectedIndexChangedEvent.

Hope this helps. Not sure if this is what you need or not. Sorry if off base.
Last edited by jbrock31; Feb 24th, 2009 at 8:29 pm.
Reputation Points: 22
Solved Threads: 14
Junior Poster in Training
jbrock31 is offline Offline
73 posts
since Oct 2008
Feb 24th, 2009
0

Re: Combo Box Help

It really didn't do anything..thanks anyways
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Feb 24th, 2009
0

Re: Combo Box Help

What did you try? I didnt give any exact code as im sure you know. Show us some code. If i can't help, i'm sure another will.
Last edited by jbrock31; Feb 24th, 2009 at 9:39 pm.
Reputation Points: 22
Solved Threads: 14
Junior Poster in Training
jbrock31 is offline Offline
73 posts
since Oct 2008
Feb 24th, 2009
0

Re: Combo Box Help

so far i tried this and i got it to show "coke" in SpecificComboBox when i selected "soda" in GeneralComboBox...

Private Sub xGeneralComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xGeneralComboBox.SelectedIndexChanged

If xGeneralComboBox.Text = "Soda" Then
xSpecificComboBox.Text = "Coke"

End If

However, it i want the dropdown list to also show the other soda specific items only, not just one..if i add more stuff like
xSpecificComboBox.Text = "Sprite"
xSpecificComboBox.Text = "Fanta"

to continue the code below the "coke" but above the "end if" the sprite and fanta don't show.

I've done so many statements, with different combinations now every sees to look the same....
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Feb 24th, 2009
0

Re: Combo Box Help

I just create something in like 5 mins. This works for me. At form load i set enabled property of specific combo to false.

In the SelectedIndexChanged event for general combo box i enable the specific box and add the items based on the selected index. this is very basic and could be changed around if you needed it to be more sophisticated, but i was giving you a basic idea of how you could do what you were wanting.

vb Syntax (Toggle Plain Text)
  1. Private Sub cmbGeneral_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbGeneral.SelectedIndexChanged
  2.  
  3. cmbSpecific.Enabled = True
  4. cmbSpecific.Items.Clear()
  5.  
  6. If cmbGeneral.SelectedIndex = 0 Then
  7. cmbSpecific.Items.Add("Sprite")
  8. cmbSpecific.Items.Add("Dr. Pepper")
  9. ElseIf cmbGeneral.SelectedIndex = 1 Then
  10. cmbSpecific.Items.Add("Apple Juice")
  11. cmbSpecific.Items.Add("Orange Juice")
  12. End If
  13. End Sub
  14.  
  15. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  16.  
  17. cmbSpecific.Enabled = False
  18.  
  19. End Sub
  20. End Class
Reputation Points: 22
Solved Threads: 14
Junior Poster in Training
jbrock31 is offline Offline
73 posts
since Oct 2008
Feb 26th, 2009
0

Re: Combo Box Help

Ohhhhhhhhhhhhhhhhhhhhh I feel so dumb!!! I tried it and it worked...exactly what i was looking to do...i was stuck using this code:

If
Me.xGeneralComboBox.textselected =="Soda" then

Me.xSpecificComboBox.format("Sprite", "Fanta")

then i tried inheritance and i couldn't understand what i was doing...Thanks Alot!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Feb 26th, 2009
0

Re: Combo Box Help

I figured it out now, thanks everyone...

I used the Case Select method and i was able to add more things in A that B could Use (hopefully u get what am saying)
Reputation Points: 10
Solved Threads: 0
Light Poster
bondgirl21 is offline Offline
41 posts
since Feb 2009
Feb 26th, 2009
0

Re: Combo Box Help

Awesome. Glad you got it figured out. Good luck.
Reputation Points: 22
Solved Threads: 14
Junior Poster in Training
jbrock31 is offline Offline
73 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to Change Cell Backcolor if Datagridview2.item.value = Datagridview1.item.value
Next Thread in VB.NET Forum Timeline: DEADLOCK





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC