Mike abban

Mike abban

  • NA
  • 10
  • 25.9k

How to call a method when a datagridview cell value change

Aug 15 2013 3:40 PM
i have a datagridview and a button on my form. when values are entered into the 2 cells of the
datagridview and the button is pressed, the numbers are multiplied and the result is displayed in the third cell. this works alright. i now want the multiplication to be done automaticaly without pressing the button. that is when the value of the cell change it should call the function responsible for the calculation.
i tryed this but it keeps genetrating the error
An unhandled exception of the type 'System.StackOverflowException' occurred in System.Data.dll
please help me out
the codes

 

public void multiplyrows()

        {

            for (int i = 0; i < dgvSales.Rows.Count - 1; i++)

            {

                double a = Convert.ToDouble(dgvSales.Rows[i].Cells["Quantity Sold"].Value);

                double b = Convert.ToDouble(dgvSales.Rows[i].Cells["Unit Price"].Value);

 

                this.dgvSales.Rows[i].Cells[5].Value = (a*b).ToString("0.00");

            }

        }

 

 

private void dgvSales_CellValueChanged(object sender, DataGridViewCellEventArgs e)

        {

            multiplyrows();

           

        }


Answers (3)