Calculation in a DataGrid. W#

0

Hello. Is there any simple way, working directly with db of doing calculations in the cell of a DataGrid.

Situation:
I have a Column Qtd , another ValorUnitario and another ValorTotal of a certain item. I would like the column ValorTotal to show the result of Qtd * UnitValue.

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

    
asked by anonymous 15.08.2016 / 15:18

1 answer

3

It goes into the DataGridView EndEdit Event and does the calculation, that is, at the end of editing a cell performs some function. More like this:

 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;

        }
    
15.08.2016 / 15:28