Doing calculation in a datagrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Belee

    #1

    Doing calculation in a datagrid

    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_ CurrentCellChan ged(object sender,
    System.EventArg s e)
    {
    decimal result = 0;
    decimal price = 0;
    decimal qty = 0;
    try
    {

    price = Convert.ToDecim al
    (this.dtcPrice. TextBox.Text);
    qty = Convert.ToDecim al
    (this.dtcQuanti ty.TextBox.Text );
    result = price * qty;

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

    MessageBoxButto ns.OK, MessageBoxIcon. Error);
    }
    }

    The datagrid uses TableStyles. I need help please.
  • Morten Wennevik

    #2
    Re: Doing calculation in a datagrid

    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.

    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

    Comment

    Working...