Linking Combo Boxes in VB 2008
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. Do i use an If/Else/ Case Else statement or what?
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")
Re: Linking Combo Boxes in VB 2008
You need to check a condition, and i f it's TRUE, you do one thing, and if it's FALSE, you do the other.
If you type IF and a space, you will see syntax that's needed.
If you have troubles, paste what you've tried into a post.
Code:
' using CODE TAGS like this
and we'll help you straighten it out. (really sounds like homework though)
Re: Linking Combo Boxes in VB 2008
Hi,
Ok when i tried this code:
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.xGeneralComboBox.SelectedIndex = 0
Me.xSpecificComboBox.SelectedIndex = 1
Me.xModelComboBox.Enabled = False
---------------------------------------------------------------
Private Sub xGeneralComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xGeneralComboBox.SelectedIndexChanged
Me.xSpecificComboBox.Enabled = True
Me.xSpecificComboBox.Items.Clear()
If Me.xgeneralComboBox.SelectedIndex = 0 Then
Me.xSpecificlComboBox.Items.Add("Sprite")
Me.xModelComboBox.Items.Add("Fanta")
Me.xModelComboBox.Items.Add("coke")
Else
Me.xgeneralComboBox.SelectedIndex = 1
Me.xGeneralComboBox.Items.Add("Apple")
Me.xGeneraComboBox.Items.Add("Grape")
Me.xGeneraComboBox.Items.Add("Pear")
End If
and it worked fine for just two things...i'm playing around with it to make it work for atleast 4 things in General Combo Box that can be selected then the values displayed in Combo box B....
.
Any ideas?
..
Re: Linking Combo Boxes in VB 2008
Quote:
Originally Posted by
bondgirl21
Hi,
Ok when i tried this code:
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.xGeneralComboBox.SelectedIndex = 0
Me.xSpecificComboBox.SelectedIndex = 1
Me.xModelComboBox.Enabled = False
---------------------------------------------------------------
Private Sub xGeneralComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xGeneralComboBox.SelectedIndexChanged
Me.xSpecificComboBox.Enabled = True
Me.xSpecificComboBox.Items.Clear()
If Me.xgeneralComboBox.SelectedIndex = 0 Then
Me.xSpecificlComboBox.Items.Add("Sprite")
Me.xModelComboBox.Items.Add("Fanta")
Me.xModelComboBox.Items.Add("coke")
Else
Me.xgeneralComboBox.SelectedIndex = 1
Me.xGeneralComboBox.Items.Add("Apple")
Me.xGeneraComboBox.Items.Add("Grape")
Me.xGeneraComboBox.Items.Add("Pear")
End If
and it worked fine for just two things...i'm playing around with it to make it work for atleast 4 things in General Combo Box that can be selected then the values displayed in Combo box B....
.
Any ideas?
..
I used the Case Select Statement and now it's all sorted out..
Re: Linking Combo Boxes in VB 2008
You can build a :
Code:
IF [condition]
....
ELSEIF [condition]
....
ELSEIF [condition]
....
ELSE
....
END IF
Or you could also use a Select
Code:
Select Case [Variable]
Case [value]
.....
Case [value]
.....
Case [value]
.....
Case [value]
.....
Case Else
.....
End Select
Gremmy...
---Edit---
You Posted while i was typing this reply ...
Re: Linking Combo Boxes in VB 2008
Quote:
Originally Posted by
GremlinSA
You can build a :
Code:
IF [condition]
....
ELSEIF [condition]
....
ELSEIF [condition]
....
ELSE
....
END IF
Or you could also use a Select
Code:
Select Case [Variable]
Case [value]
.....
Case [value]
.....
Case [value]
.....
Case [value]
.....
Case Else
.....
End Select
Gremmy...
---Edit---
You Posted while i was typing this reply ...
thanks, i'll put this down in my notes!