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

问题描述 投票:0回答:2

我使用了WinUI的Telerik样本中的Grid 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

c# winforms gridview telerik-grid winui
2个回答
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);
}

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);
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.