CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    8

    Post 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")

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2009
    Posts
    8

    Question 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?
    ..

  4. #4
    Join Date
    Feb 2009
    Posts
    8

    Resolved Re: Linking Combo Boxes in VB 2008

    Quote Originally Posted by bondgirl21 View Post
    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..

  5. #5
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    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.

  6. #6
    Join Date
    Feb 2009
    Posts
    8

    Smile Re: Linking Combo Boxes in VB 2008

    Quote Originally Posted by GremlinSA View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured