-
February 24th, 2009, 06:37 PM
#1
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")
-
February 24th, 2009, 06:47 PM
#2
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)
-
February 26th, 2009, 04:33 AM
#3
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?
..
-
February 26th, 2009, 05:29 AM
#4
Re: Linking Combo Boxes in VB 2008
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..
-
February 26th, 2009, 05:32 AM
#5
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 ...
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
February 26th, 2009, 05:59 AM
#6
Re: Linking Combo Boxes in VB 2008
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!
Tags for this Thread
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
|