Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
Posted
Updated 10-Oct-14 1:59am
v4

1 solution

 
Share this answer
 
Comments
Sunilk3 10-Oct-14 9:43am    
Hi Gihan,
above link worked with row background color but this is not working with cell background color when scrolling, background color disappears.

Do you have anything regarding this problem?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900