Connecting Tech Pros Worldwide Help | Site Map

Assigning values to Combo Box Items

Newbie
 
Join Date: Feb 2009
Posts: 20
#1: Feb 27 '09
Hi,
I used this code to created 2 combo boxes General and Specific...and Only show Specific (Combo B) when Combo A is chosen.....
  • What i need now is to know how to assign specific values to the items in combo b (Specific).???
If i chose a sode, Fanta, i want the total price to be $20.00 (this price will show up in the finial price box....Please Help!!

Expand|Select|Wrap|Line Numbers
  1.  drinkComboBox.Items.Clear() 'Clears the old items out of the drinkComboBox
  2.  
  3.         If typeComboBox.SelectedText = "Soda" Then 'If the user selected Soda then...
  4.             drinkComboBox.Items.Add("Fanta")  'Add soda drinks to the drinkComboBox
  5.             drinkComboBox.Items.Add("Sprite")
  6.             drinkComboBox.Items.Add("Coke")
  7.         End If
  8.  
  9.         If typeComboBox.SelectedText = "Juice" Then 'If the user selected Juice then...
  10.             drinkComboBox.Items.Add("Apple") 'Add juices to drinkComboBox
  11.             drinkComboBox.Items.Add("Grape")
  12.             drinkComboBox.Items.Add("Pear")
  13.         End If
  14.  
  15.       Private Sub xGeneralComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xGeneralComboBox.SelectedIndexChanged
  16.  
  17.           Me.xSpecificComboBox.Enabled = True
  18.  
  19.           Me.xSpecificComboBox.Items.Clear()
  20.  
  21.           Select Case Me.xgeneralComboBox.SelectedText
  22.  
  23.               Case "Soda"
  24.  
  25.                   Me.xSpecificComboBox.Items.Add("Sprite")
  26.  
  27.                   Me.xSpecificComboBox.Items.Add("Fanta")
  28.  
  29.                   Me.xSpecificComboBox.Items.Add("coke")
  30.  
  31.               Case "Juice"
  32.                     Me.xSpecificComboBox.Items.Add("Apple")
  33.  
  34.                   Me.xSpecificComboBox.Items.Add("Grape")
  35.  
  36.                   Me.xSpecificComboBox.Items.Add("Pear")  
  37.  
  38.            End Select
  39.         End Sub
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 699
#2: Mar 4 '09

re: Assigning values to Combo Box Items


What problem are you facing?

MSDN


Take a look at this ....
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. string[] alVar ={ "1","2","3"};
  4.             comboBox1.Items.AddRange(alVar);
  5.  
  6.  
  7.  
  8.  
  9.  
  10. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  11.         {
  12.             if (comboBox1.SelectedIndex != -1)
  13.             {
  14.                 comboBox2.Visible = true;
  15.  
  16.                 string[] one ={"11","111","1111" };
  17.                 string[] two ={"22","2222" }; 
  18.                 string temp=comboBox1.SelectedItem.ToString();
  19.                 comboBox2.Items.Clear();
  20.                 switch (temp)
  21.                 {
  22.                     case "1":
  23.                         comboBox2.Items.AddRange(one);
  24.                         break;
  25.                     case "2":
  26.                         comboBox2.Items.AddRange(one);
  27.                         break;
  28.                     default:
  29.                         break;
  30.                 }
  31.  
  32.                 if (comboBox2.Items.Count > 0)
  33.                 {
  34.                     comboBox2.SelectedIndex = 1;
  35.                 }
  36.             }
  37.         }
  38.  
Newbie
 
Join Date: Feb 2009
Posts: 20
#3: Mar 6 '09

re: Assigning values to Combo Box Items


thanks..i solved it.
Reply

Tags
combo box, visual basic