Doing calculation in a datagrid

B

Belee

I am doing calculation in a data grid and I get the
following error message: "Input format not in correct
format".

The following is the code in c#
private void
dgSalesInvoice_CurrentCellChanged(object sender,
System.EventArgs e)
{
decimal result = 0;
decimal price = 0;
decimal qty = 0;
try
{

price = Convert.ToDecimal
(this.dtcPrice.TextBox.Text);
qty = Convert.ToDecimal
(this.dtcQuantity.TextBox.Text);
result = price * qty;

this.dtcAmount.TextBox.Text = result.ToString();
}
catch (Exception eC)
{
MessageBox.Show
(eC.Message, eC.GetType().ToString(),

MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

The datagrid uses TableStyles. I need help please.
 
M

Morten Wennevik

Well, upon converting to decimal, are you using ',' or '.' in the decimal
number? If you use the wrong one (you should use ',' I believe) you will
get invalid format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top