view and add sub items of each item of the combo box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • myanmaraladin
    New Member
    • Feb 2010
    • 1

    view and add sub items of each item of the combo box

    i recently add two combo boxes in my form. the first combo box contains the categories of movies. and the other one is the list of movies sorted according to the category of movie. i just wondering how i could i add and view movies for the second combo box, when i click one of the category of movie. thank you..
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Combobox has a property of .Items that you populate with the things you want it to display.

    Comment

    • lotus18
      Contributor
      • Nov 2007
      • 865

      #3
      Hi myanmaraladin,

      You can use a nested if-else statement or a select case. Under the SelectedIndexCh anged event of your combobox1 (assuming this is your list of categories) try this:

      Code:
      if combobox1.Text = "Action" Then
           combobox2.Items.Clear()
           combobox2.Items.Add("Action Movie 1")
           combobox2.Items.Add("Action Movie 2")
           combobox2.Items.Add("Action Movie 3")
      ElseIf combobox1.Text = "Sci-Fi" Then
           combobox2.Items.Clear()
           combobox2.Items.Add("Avatar")
           combobox2.Items.Add("Transformers")
           combobox2.Items.Add("X-Men")
      ElseIf combobox1.Text = "Comedy"
           combobox2.Items.Clear()
           combobox2.Items.Add("Ang Tanging Ina")
           combobox2.Items.Add("Paano Na Kaya?")
           combobox2.Items.Add("Agent X44")
      End If
      Or you can also use AddRange Method
      Code:
      combobox1.Items.AddRange(New Object() {"Action Movie 1", "Action Movie 2", "Action Movie 3"})

      Rey Sean
      Last edited by lotus18; Feb 10 '10, 03:29 PM. Reason: combox2 has been changed to combobox2

      Comment

      Working...