如果滚动

时间:2015-05-22 09:35:04

标签: c# winforms gridview telerik-grid

我在Telerik样本中使用了网格WinUI C:\ Program Files(x86)\ Telerik \ UI for WinForms Q1 2015 \ Examples \ QuickStart \ GridView \ Rows \ AddNewRow \ Form1.cs并添加了以下代码以获取UnitPrice采用蓝色字体:

 public Form1()
    {
       ...
        this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);
    }

        void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridDataCellElement dataCell = e.CellElement as GridDataCellElement;
        if (dataCell != null)
        {
            if (dataCell.ColumnInfo.Name.ToLower() == "unitprice")
            {
                dataCell.ForeColor = System.Drawing.Color.Blue;
                dataCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
            }
        }
    }

首次加载表单时,这是有效的:

enter image description here

如果我垂直滚动表单,其他一些列也会变蓝。我能做点什么吗?

enter image description here

2 个答案:

答案 0 :(得分:1)

应为其他列重置自定义

 if (dataCell.ColumnInfo.Name.ToLower() == "unitprice")
        {
            dataCell.ForeColor = System.Drawing.Color.Blue;
            dataCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
        }

else
{
e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
}

答案 1 :(得分:0)

单元格格式中尝试此操作,更改了if条件

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
   if (e.CellElement.ColumnInfo.Name == "unitprice")
   {
    dataCell.ForeColor = System.Drawing.Color.Blue;
    dataCell.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0);
   }
}