Doing calculation in a datagrid

  • Thread starter Thread starter Belee
  • Start date Start date
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.
 
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.
 
Back
Top