如何从代码后面维护radgridview单元格的背景颜色? [英] how to maintain background color of radgridview cell from code behind?

查看:128
本文介绍了如何从代码后面维护radgridview单元格的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式应用radgridview单元格的背景颜色?当我向上或向下滚动时,我发现背景颜色不再存在。

xaml.cs

How can I apply background color of radgridview cell programatically ? I have found that background color no longer exists when I scroll up or down.
xaml.cs

private void dgQueue_RowLoaded(object sender, RowLoadedEventArgs e)
{
    GridViewRow GrdRow = e.Row as GridViewRow;
    EVQueue objEV = e.Row.DataContext as EVQueue;
    TextBlock txtActivityDate = null;
    TextBlock txtSendDate = null;
    int activityDateIndex = 0;
    if (GrdRow != null)
    {
        for (int index = 0; index < GrdRow.Cells.Count; index++)
        {
            if (GrdRow.Cells[index].Column.UniqueName.Equals("ActivityDate", StringComparison.OrdinalIgnoreCase))
            {
                if (objEV.ActivityDate != null)
                {
                    txtActivityDate = (TextBlock)e.Row.Cells[index].Content;
                    activityDateIndex = index;
                }
            }

            if (GrdRow.Cells[index].Column.UniqueName.Equals("SendDate", StringComparison.OrdinalIgnoreCase))
            {
                if (objEV.SendDate != null)
                {
                    txtSendDate = (TextBlock)e.Row.Cells[index].Content;
                }
            }
        }
        if (!string.IsNullOrEmpty(txtActivityDate.Text) && !string.IsNullOrEmpty(txtSendDate.Text))
        {
            if (Convert.ToDateTime(txtActivityDate.Text, CultureInfo.InvariantCulture) > Convert.ToDateTime(txtSendDate.Text, CultureInfo.InvariantCulture))
            {
                e.Row.Cells[activityDateIndex].Background = Brushes.Yellow;
            }
        }
    }
}



xaml

<telerik:radgridview name="dgQueue" xmlns:telerik="#unknown">
Grid.Row="2"
Grid.Column="0"
Height="580"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
AutoGenerateColumns="False"
FontSize="12"
IsReadOnly="True"
ItemsSource="{Binding}"
ShowColumnFooters="true"
ShowGroupPanel="False"
telerikControls:StyleManager.Theme="Summer"
UseLayoutRounding="True"
RowLoaded="dgQueue_RowLoaded"
AllowDrop="False" TabIndex="14" >
<telerik:radgridview.columns>
<telerik:gridviewdatacolumn width="*" uniquename="ActivityDate" name="datacolActivityDate">
DataMemberBinding="{Binding ActivityDate}"
Header="Activity Date" />

<telerik:gridviewdatacolumn width="*" uniquename="SendDate">
DataMemberBinding="{Binding SendDate}"
Header="Send Date" />
</telerik:gridviewdatacolumn></telerik:gridviewdatacolumn></telerik:radgridview.columns>
</telerik:radgridview>

推荐答案

查看此文章



http://humrahimcs.wordpress.com/2011/12 / 19 / change-color-for-radgrid-rows / [ ^ ]


这篇关于如何从代码后面维护radgridview单元格的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆