将单元格格式设置为第二行直到用户单击?

时间:2017-08-07 12:41:39

标签: winforms datagridview

我正在使用一些代码使单元格颜色处于活动状态,这是红色和白色但是出于某种原因,当用户点击单元格时它会正确触发并根据同一行中另一个单元格中的条件绘制两个单元格它是一个百分比。但由于某种原因,它只是第二排的主要原因而且我不知道为什么。

我在以下活动中使用它

  

private void dgUpdatesPrices_CellFormatting(object sender,   DataGridViewCellFormattingEventArgs e)

  /// </summary>
    public void checkSPSThreasholds(double _oldPrice, double _newPrice, DataGridViewRow dgr)
    {
        foreach (DataGridViewRow Row in dgUpdatesPrices.Rows)

        {
            if (_priceListType == "SPS")
            {
                Double _percentage = calculatePercentageDiff(_oldPrice, _newPrice);
                dgr.Cells["SPercentage"].Value = _percentage.ToString();

                if (_percentage > 1.2)
                {
                    ValidateProducts _validateProduct = new ValidateProducts();

                    dgr.Cells["NSPSPRICE"].Style.BackColor = Color.Red;
                    dgr.Cells["NSPSPRICE"].Style.ForeColor = Color.White;

                    _validateProduct.ValidationMessage = "Product is above threshold, please adjust.";
                    if (dgr.Cells["NSPSPRICE"].Value.ToStringOrEmpty() != "")
                    {
                        _validateProduct.price = Convert.ToDecimal(dgr.Cells["NSPSPRICE"].Value);
                    }
                    _validateProduct.ValidationProduct = dgr.Cells["Description"].Value.ToString();
                    _validatePrices.Add(_validateProduct);
                }

                if (_percentage < 0.8)
                {
                    ValidateProducts _validateProduct = new ValidateProducts();

                    dgr.Cells["NSPSPRICE"].Style.BackColor = Color.Red;
                    dgr.Cells["NSPSPRICE"].Style.ForeColor = Color.White;

                    _validateProduct.ValidationMessage = "Product is below threshold, please adjust.";
                    if (dgr.Cells["NSPSPRICE"].Value.ToStringOrEmpty() != "")
                    {
                        _validateProduct.price = Convert.ToDecimal(dgr.Cells["NSPSPRICE"].Value);
                    }
                    _validateProduct.ValidationProduct = dgr.Cells["Description"].Value.ToString();
                    _validatePrices.Add(_validateProduct);
                }

                if (_percentage == 0)
                {
                    dgr.Cells["NSPSPRICE"].Style.BackColor = Color.White;
                    dgr.Cells["NSPSPRICE"].Style.ForeColor = Color.Black;
                }
            }
        }
    }

根据百分比列中的内容,它应该以新的sps价格绘制两个单元格,一旦用户点击上面的单元格,我就会错过重绘功能。

enter image description here

你应该看到原因百分比列显示大于20的第一个百分比它应该被涂上与第二行相同的颜色现在当我点击第二个单元格时它描绘它很好这是一个案例全行选择可能干扰。

0 个答案:

没有答案
相关问题