Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stackoverflow exception during during DGV cell value change Event triggers

i am trying to multiply the value of two cells from DGV and saving it to another cell.
but aim getting stackOverFlow Exception.

        private void ReturnCartDGV_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            long totalPrice;
            int rowIndex = ReturnCartDGV.CurrentCell.RowIndex;
            totalPrice = (Convert.ToInt64(ReturnCartDGV.Rows[rowIndex].Cells[4].Value) * Convert.ToInt64(ReturnCartDGV.Rows[rowIndex].Cells[5].Value));
            this.ReturnCartDGV.Rows[rowIndex].Cells[6].Value = totalPrice.ToString();
            
        }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are changing the Value of a cell in the CellValueChanged event handler, which will raise the CellValueChanged event, which will continue on ad infinitum until the stack overflows. You are only interested in the Value changing in two specific columns, so you should be checking whether the event was raised by a cell in either of those two columns. If it wasn’t then you don’t do anything. The e parameter will tell you which column the cell was in whose Value changed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading