I have a combo box that has product types and the associated prices that go with them. I need to take the value member of the combo box which is the price and convert it to multiply it against another value and be able to put it in an invoice as currency. Currently I can convert it to string but it seems I cannot just use a .ToString(“C”) overload to change it to currency. Any help would be great:
private void btnAddProduct_Click(object sender, EventArgs e)
{
double invoiceTotal;
double productTotal;
double currentTotal;
string multiplier;
string price;
//invoiceTotal = 0;
price = Convert.ToString(comboBox1.SelectedValue);
multiplier = comboBox2.Text;
productTotal = Convert.ToDouble(txtProductTotal.Text);
if (txtInvoiceTotal.Text != "")
{
invoiceTotal = Convert.ToDouble(txtInvoiceTotal.Text);
}
else
{
invoiceTotal = 0;
}
currentTotal = productTotal + invoiceTotal;
txtInvoiceTotal.Text = Convert.ToString(currentTotal);
string prod = comboBox1.Text;
if (txtExplanation.Text == "")
{
txtExplanation.Text = prod + " X " + multiplier + " @ " + price;
}
else
txtExplanation.Text = txtExplanation.Text + "\r\n" + prod + " X " + multiplier + " @ " + price;
}
comboBox1.SelectedValue should already be a string. So you might want to then use String.Format to format it the way you want it. Otherwise, you could parse it into the double with Double.Parse(comboBox1.SelectedValue) and then call ToString(“C”) on the double value.