C# combobox

how to add assigned combobox values together

Page 1 of 1

2 Replies - 5032 Views - Last Post: 16 April 2009 - 06:41 PM Rate Topic: -----

#1 RLRNY  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-November 07

C# combobox

Posted 16 April 2009 - 04:02 PM

i am having trouble figuring out how to add the prices i stored in the combo box

and also adding an double variable tax to the total
 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace chw
{
public partial class Form1 : Form
{
class userData
{

private double _value;
private string _name;

public double Value
	
{
get { return _value; }set { _value = value; }
}
public string Name
{

get { return _name; }set { _name = value; }

}
public userData(string name, double value )

{

_name = name;

_value = value;

}
public override string ToString()

{
return _name;
}
}
public Form1()
		{
			InitializeComponent();
			comboBox1.Items.Add(new userData("Soda", 1.95));
			comboBox1.Items.Add(new userData("Tea", 1.50));
			comboBox1.Items.Add(new userData("Cofee", 1.25));
			comboBox1.Items.Add(new userData("Mineral Water", 2.95));
			comboBox1.Items.Add(new userData("Juice", 2.50));
			comboBox1.Items.Add(new userData("Milk", 1.50));
			
			comboBox2.Items.Add(new userData("Buffalo Wings", 5.95));
			comboBox2.Items.Add(new userData("Buffalo Fingers", 6.95));
			comboBox2.Items.Add(new userData("Potatoe Skins", 8.95));
			comboBox2.Items.Add(new userData("Nachos", 8.95));
			comboBox2.Items.Add(new userData("Mushroom Caps", 10.95));
			comboBox2.Items.Add(new userData("Shrimp CockTail",12.95));
			comboBox2.Items.Add(new userData("Chips And Salsa", 6.95));

			comboBox3.Items.Add(new userData("Seafood Alfredo",15.95));
			comboBox3.Items.Add(new userData("Chicken Alfredo",13.95));
			comboBox3.Items.Add(new userData("Chicken Picatta",13.95));
			comboBox3.Items.Add(new userData("Turkey Club", 11.95));
			comboBox3.Items.Add(new userData("Lobster Pie", 19.95));
			comboBox3.Items.Add(new userData("Prime Rib", 20.95));
			comboBox3.Items.Add(new userData("Shrimp Scampi", 18.95));
			comboBox3.Items.Add(new userData("Turkey Dinner", 13.95));
			comboBox3.Items.Add(new userData("Stuffed chicken",14.95));

			comboBox4.Items.Add(new userData("Apple Pie", 5.95));
			comboBox4.Items.Add(new userData("Sundae", 3.95));
			comboBox4.Items.Add(new userData("Carrot cake", 5.95));
			comboBox4.Items.Add(new userData("Mudd Pie", 4.95));
			comboBox4.Items.Add(new userData("Apple crisp", 5.95));

			}

		private void Form1_Load(object sender, EventArgs e)
		   
		{
		   
   
		}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
	   userData selectedData = (userData)comboBox1.SelectedItem;							 label11.Text = selectedData.Name + ":" + selectedData.Value;
	}

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
		{
	   userData selectedData = (userData)comboBox2.SelectedItem; label14.Text = selectedData.Name + ":" + selectedData.Value;
   
			
		}

private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
		{
	   userData selectedData = (userData)comboBox3.SelectedItem; label15.Text = selectedData.Name + ":" + selectedData.Value;
   
		}

private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
		{
	   userData selectedData = (userData)comboBox4.SelectedItem; label16.Text = selectedData.Name + ":" + selectedData.Value;
	  
		}


Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: C# combobox

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: C# combobox

Posted 16 April 2009 - 05:20 PM

Since it looks like you don't want to use arrays try creating a variable for each value like this:

double value1;
double value2;
double value3;
double value4;



In the methods where you handle the change event for each event assign the appropriate value for the corrosponding combobox, for combobox1 use value1, combobox2 use value2, etc. Try that to get the values for each combobox.
Was This Post Helpful? 0
  • +
  • -

#3 RLRNY  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-November 07

Re: C# combobox

Posted 16 April 2009 - 06:41 PM

View PostSixOfEleven, on 16 Apr, 2009 - 04:20 PM, said:

Since it looks like you don't want to use arrays try creating a variable for each value like this:

double value1;
double value2;
double value3;
double value4;



In the methods where you handle the change event for each event assign the appropriate value for the corrosponding combobox, for combobox1 use value1, combobox2 use value2, etc. Try that to get the values for each combobox.




thanks i was able to complete program with your help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1