Telerik WinUI GridView 在滚动时使用错误单元格的格式

Telerik WinUI GridView uses formating for wrong cell if scrolled

我在 WinUI C:\Program Files (x86)\Telerik\UI 的 WinForms Q1 2015\Examples\QuickStart\GridView\Rows\AddNewRow\Form1.cs 的 Telerik 示例中使用了网格,并添加了以下代码以获取蓝色的单价字体:

 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);
            }
        }
    }

表单首次加载时有效:

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

单元格格式 中试试这个,更改 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);
   }
}

应为其他列重置自定义设置

 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);
}