Reputation: 25
I am doing a clothing shop program and my code is this.
cbmale.Items.Add(new Data { Name = "Male Shirt", Value = "10.0f" });
cbmale.Items.Add(new Data { Name = "Male Jeans", Value = "20.0f" });
cbmale.Items.Add(new Data { Name = "Male Pants", Value = "20.0f" });
cbmale.Items.Add(new Data { Name = "Male Socks", Value = "20.0f" });
cbmale.Items.Add(new Data { Name = "Male Hoodie", Value = "20.0f" });
cbmale.DisplayMember = "Name";
cbmale.ValueMember = "Value";
private void button1_Click(object sender, EventArgs e)
{
int quantity = (int)nudmale.Value;
bool isRBchecked = rbsmallmale.Checked || rbmediummale.Checked || rblargemale.Checked;
if (isRBchecked == false)
{
MessageBox.Show("Please select a size of the selected male item");
totalpricemale = 0.0f;
}
if (string.IsNullOrEmpty(cbmale.Text))
{
MessageBox.Show("No Item is Selected");
}
else
{
MessageBox.Show("Item Selected is:" + cbmale.Text);
}
totalpricemale = totalpricemale + quantity *
lblmale.Text = totalpricemale.ToString("C");
}
So how do i use the values that i have inserted to calculate the total price of the items selected? Right now my formula for calculating is this totalpricemale = totalpricemale + quantity So how do i include the value in this formula?
Upvotes: 0
Views: 4642
Reputation: 2272
Are you asking how to actually pull the values you have stored in the combo box?
cbmale.SelectedItem
Will return the Data object stored in the Combobox that is currently selected.
If what you are trying to do is get the currently selected item in the combobox, then multiply its price by the quantity stored in nudmale.Value
then you should do this:
totalpricemale = totalpricemale + (quantity * cbmale.SelectedItem.Value);
Edit: I don't know what Data object this is, I'm not sure if .Value will get you what you are looking for, but you should get the point.
Upvotes: 1