0

我在 WinUI C:\Program Files (x86)\Telerik\UI for WinForms Q1 2015\Examples\QuickStart\GridView\Rows\AddNewRow\Form1.cs 的 Telerik 示例中使用了网格,并添加了以下代码以获取 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);
            }
        }
    }

这在表单首次加载时有效:

在此处输入图像描述

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

在此处输入图像描述

4

2 回答 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);
}
于 2015-05-22T16:01:34.223 回答
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);
   }
}

于 2015-05-22T09:42:35.617 回答