Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# RadGridView更改文本颜色_C#_Wpf_Telerik_Telerik Grid_Radgridview - Fatal编程技术网

C# RadGridView更改文本颜色

C# RadGridView更改文本颜色,c#,wpf,telerik,telerik-grid,radgridview,C#,Wpf,Telerik,Telerik Grid,Radgridview,我有一个简单的RadGridView,其中我想更改特定行(=3个单元格)的文本颜色。不幸的是,此代码不起作用: //add new row to the grid EventLogGrid.Items.Add(new EventLogRow(eventType, occured, msg)); //change the color of the text of all cells if it's an exception if (eventType == EventLogger.EventTy

我有一个简单的
RadGridView
,其中我想更改特定行(=3个单元格)的文本颜色。不幸的是,此代码不起作用:

//add new row to the grid
EventLogGrid.Items.Add(new EventLogRow(eventType, occured, msg));

//change the color of the text of all cells if it's an exception
if (eventType == EventLogger.EventType.Exception)
{
  var rows = this.EventLogGrid.ChildrenOfType<GridViewRow>();
  rows.Last().Foreground = new SolidColorBrush(Colors.Yellow);
}
//将新行添加到网格
添加(新的EventLogRow(eventType,Occursed,msg));
//如果出现异常,请更改所有单元格文本的颜色
if(eventType==EventLogger.eventType.Exception)
{
var rows=this.EventLogGrid.ChildrenOfType();
rows.Last().前台=新的SolidColorBrush(Colors.Yellow);
}

如果您有任何意见,我们将不胜感激。

请尝试类似的内容。Telerik网站也有大量精彩的示例

或者这可以为你工作我已经测试过了,它可以工作。如果你给我列名,请确保用你的列名替换列名,因为你有3列,我需要第一个列名。。希望这对你有意义

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        TableCell cell = (TableCell)item["YourColumnName"];
        cell.BackColor = System.Drawing.Color.Yellow;
    }
}

实际上有一个非常简单的解决方案:

  • 附加事件处理程序:

    EventLogGrid.RowLoaded += EventLogGrid_RowLoaded;
    
  • 更改行的颜色:

    if (((EventLogRow)e.DataElement).MsgType == EventLogger.EventType.Exception)
    {
       e.Row.Foreground = new SolidColorBrush(Colors.Red);
    }
    

  • “不起作用”是什么意思?错误是什么?更具体一点。你看过Telerik网站上的文档了吗。。?他们有大量的工作要做examples@SonerGönül:没有错误,它只是不会更改文本的颜色。Mike为什么不使用此事件开始编写代码来更改颜色。。protectedvoid RadGrid1_ItemDataBound(objectsender,Telerik.Web.UI.GridItemEventArgs e){}@DJ KRAZE:好的,谢谢,我现在就试试。好的,我已经测试了这段代码,它不起作用。看起来您使用的是Telerik web库,但我使用的是Telerik WPF库,它似乎有所不同。无论如何,谢谢。我有相同的库,我会更正我的答案并给你一个有效的解决方案。你在RadGrid中的第一列的名称是什么。。然后我可以发布一个你应该做什么的例子。。谢谢
    if (((EventLogRow)e.DataElement).MsgType == EventLogger.EventType.Exception)
    {
       e.Row.Foreground = new SolidColorBrush(Colors.Red);
    }