Loop messing up Datagridview Winforms cell contents

david39ni

New member
Joined
Jul 7, 2017
Messages
1
Programming Experience
5-10
I am trying to show the percentage of old and new price difference however each loop is overwriting the cell contents so it will only show either euro percentage and not the sterline what would my best away around this be. It is this line here that is causing the issue obv easy fix would be two percentage columns but I require one.

Line Causing issue
Row.Cells["Percentage"].Value = Convert.ToString(_euroPercentage) + "%";
C#:
  public void setupSterlingPcentageHighlight()        {
            foreach (DataGridViewRow Row in dgUpdatesPrices.Rows)


            {
                Double _oldPrice = Convert.ToDouble(Row.Cells["Price"].Value);
                double _newPrice = Convert.ToDouble(Row.Cells["NSterling"].Value);
                Double  _percentage = calculatePercentageDiff(_oldPrice, _newPrice);


                Row.Cells["Percentage"].Value = Convert.ToString(_percentage) + "%";




                if (_percentage > 1.2)
                {
                    dgUpdatesPrices.Rows[Row.Index].Cells["NSterling"].Style.ForeColor = Color.OrangeRed;
                }
                else
                    dgUpdatesPrices.Rows[Row.Index].Cells["NSterling"].Style.ForeColor = Color.Black;




                Double _oldEuroPrice = Convert.ToDouble(Row.Cells["CEuro"].Value);
                double _newEuroPrice = Convert.ToDouble(Row.Cells["NEuro"].Value);
                double _euroPercentage = calculatePercentageDiff(_oldEuroPrice, _newEuroPrice);
                Row.Cells["Percentage"].Value = Convert.ToString(_euroPercentage) + "%";




                if (_euroPercentage > 1.2)


                {




                    dgUpdatesPrices.Rows[Row.Index].Cells["CEuro"].Style.ForeColor = Color.OrangeRed;


                }
                else
                    dgUpdatesPrices.Rows[Row.Index].Cells["CEuro"].Style.ForeColor = Color.Black;





            }
 
Back
Top Bottom