This is a migrated thread and some comments may be shown as answers.

Row Background color is not stable with vertical scrolling

5 Answers 263 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Libertad
Top achievements
Rank 1
Libertad asked on 19 Mar 2012, 01:54 PM
I change the row background in code behind. It works but when I scroll the grid down or up, some other rows background is changed.
What's my problem?

private void gridContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    var menu = (RadContextMenu)sender;
    var clickedItem = e.OriginalSource as RadMenuItem;
    var row = menu.GetClickedElement<GridViewRow>();
 
    if(clickedItem != null && row != null)
    {
        var header = Convert.ToString(clickedItem.Header);
        if (header == Resource.MenuItem_View)
        {
            Foo();
            row.Background = new SolidColorBrush(Color.FromArgb(100, 133, 227, 55));
        }
    }
}

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 19 Mar 2012, 02:00 PM
Hi,

By default RadGridView has the RowVirtualization turned on. This means that it will reuse/recycle rows when scrolling  in order to boost performance. This is the reason for the side effect you are observing - containers reused for another data item persist their color.  You can easily confirm this by simply temporary disabling row virtualization RadGridView.EnableRowVirtualization = false;

The solution would be to use row style selector.

All the best,
Pavel Pavlov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Libertad
Top achievements
Rank 1
answered on 19 Mar 2012, 11:38 PM
I set RowVirtualization to false but the background color is not stable still.
0
Sunil
Top achievements
Rank 1
answered on 16 Sep 2014, 02:12 PM
RadGridView.EnableRowVirtualization = false

this is working in my code.
Now cell background color is stable


Thank you :)
0
Sunil
Top achievements
Rank 1
answered on 20 Oct 2014, 01:48 PM
Hi,
this is solved my problem.
RadGridView.EnableRowVirtualization = false



this is working in my code.

Now cell background color is stable.

But now i am facing another problem while filtering records on clicking on filter icon and again remove the filter then background color of cell is maintain but another row(just above the colored cell) of the grid also get colored with same background color.


for this problem i have a solution:
Take a Label inside DataTemplate and mark the label background color according to the condition on code behind on RowLoaded event.

and this fixed my problem

<telerik:GridViewDataColumn Header="Common Fields" UniqueName="CommonFields" Width="*" DataMemberBinding="{Binding CommonField}">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <Label Name="lblCommonFields" BorderThickness="1" Content="{Binding CommonField}" FontWeight="Normal" ></Label>
                            </StackPanel>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
  
                </telerik:GridViewDataColumn>
  Code Behind:
private void grdComparisonWindow_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            GridViewRow row = e.Row as GridViewRow;
EDI271Comparison objEV = e.Row.DataContext as EDI271Comparison;
for (int index = 0; index < row.Cells.Count; index++)
                {
                    if (row.Cells[index].Column.UniqueName.Equals("CommonFields", StringComparison.OrdinalIgnoreCase))
                    {
                        StackPanel stckpnl = (StackPanel)row.Cells[index].FindChildByType<StackPanel>();
                        lblCommonFields = (System.Windows.Controls.Label)stckpnl.Children[0];
                    }
}
if (!string.IsNullOrEmpty(careValue) && !string.IsNullOrEmpty(ediValue))
                        {
                            if (!string.Equals(careValue, ediValue))
                            {
                                lblCommonFields.Background = Brushes.Yellow;
                            }
                        }

This is my solution.

If you can suggest any inbuild solution of telerik grid for this your welcome.
0
Dimitrina
Telerik team
answered on 21 Oct 2014, 12:49 PM
Hi,

Generally, we do not recommend working with the visual elements in RadGridView as it is a virtualized control and its elements are reused as they are brought in and out the view area. You can check our online documentation explaining how the UI virtualization works. 

As to the specific problem you meet while having the row virtualization disabled, may I ask you to open a new support tickets and send us a demo project which we can check locally?

Regards,
Dimitrina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Libertad
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Libertad
Top achievements
Rank 1
Sunil
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or