473,324 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Assigning values to Combo Box Items

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
Feb 27 '09 #1
2 5027
PRR
750 Expert 512MB
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.  
Mar 4 '09 #2
thanks..i solved it.
Mar 6 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Keith | last post by:
A2003, XP Pro SP2 I have a combo box set to look up field names from a table. I want to be able to get the data type of the field chosen by the combo and assign that type to another combo box...
1
by: | last post by:
I need to assign items from an existing combobox to another empty combobox.Could you give me the code to do so.
6
by: Sebi | last post by:
Hello all, I'm thinking about overwriting the ListItem, so it can contain x additional values (not only one). Has anybody ever tried this? Has someone got an example (C#)? Can DropDownList...
5
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
4
by: tino | last post by:
I have the (usual) problem that, in a combo or listbox, I want to keep a text and a related key value. For instance the country description and the country code. In order to solve this I uss the...
0
by: JDC | last post by:
Hi all I have a GridView template field with two DropDownLists in the Edit Template. The first DropDownList is populated with a fairly standard databinding: <asp:DropDownList...
4
by: svaradan | last post by:
Hi I have a situation where in I have two combo boxes in a datagridview control. The first combo box items are all static. But the second combo box items need to change based on the first...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
0
by: bz | last post by:
Hi, I have a datagrid with two columns Region and City Both have combo-boxes. City column is unbound What I want is, when use select a region, to fill the combo for City column with appropriate...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.