Calculation in a Datagrid. C#

Asked

Viewed 543 times

0

Hello.
Is there any simple way, working directly with the db to make calculations in a datagrid cell.

Situation:
I have a Column Qtd, another ValorUnitario and another ValorTotal of a certain item. I would like in the Column ValorTotal, shows the output of Qty * Value.

This at runtime, so that if I change the quantity or unit value of a product, the result is modified as well.

1 answer

3


Go to the Event of Datagridview Endedit and calculate, that is, when finishing the edition of a cell performs some function. More so the less so:

 private void dgvTabela_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            int qt = Convert.ToInt32(dgvTabela.Rows[e.RowIndex].Cells["qtde"].Value);
            double valor= Convert.ToDouble(dgvTabela.Rows[e.RowIndex].Cells["valor"].Value);

            dgvTabela.Rows[e.RowIndex].Cells["total"].Value = qt * valor;

        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.