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

CellStyleSelector : when changing the value, the styleselector is not called

8 Answers 738 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
LE DREAU Steeve
Top achievements
Rank 1
LE DREAU Steeve asked on 07 Sep 2010, 11:34 AM
Hi All,

I'm currently facing a problem with CellStyleSelector. I have a radgridview bound to an observablecollection(of someCustomObject).
My custom object has it's Notifypropertychanged event raised into all properties.

When I first set my collection to the bound property to ItemsSource of the radgridview, the cellstyleselector "SelectStyle" function is called.
But if I change the value that should change the cell style, nothing happens, SelectStyle function is not called... 

Do you have an idea about this please?

Thanks
Regards,

Steeve

8 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 07 Sep 2010, 02:22 PM
Hello LE DREAU Steeve,

Without having your code , I may just guess what went wrong . Can you please paste me the implementation of your business object as well as some basic description with the expected behavior of the style selector  and I will try to prepare a small working sample  with it.

Kind regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 08 Sep 2010, 08:39 AM
Hi,

I cannot send you my project, but you can try a simple thing :

Create a person class with Name, Age properties.
Create a personFactory to create an observablecollection(of person) filled with some new objects.
Create a radgrid view in your main.xaml like this :

<UserControl.Resources>
    <local:MyStyleSelector x:Key="CellStyleSelector" />
</UserControl.Resources>
 
<Grid x:Name="LayoutRoot" Background="White">
    <my:RadGridView ItemsSource="{Binding MyListeOfPersons}" AutoGenerateColumns="False">
        <my:RadGridView.Columns>
            <my:GridViewDataColumn DataMemberBinding="{Binding Name}" />
            <my:GridViewDataColumn DataMemberBinding="{Binding Age}" CellStyleSelector="{StaticResource CellStyleSelector}" />
        </my:RadGridView.Columns>
    </my:RadGridView>
</Grid>

And here is the StyleSelector :

Public Class MyStyleSelector
    Inherits StyleSelector
 
    Public Overrides Function SelectStyle(ByVal item As Object, ByVal container As System.Windows.DependencyObject) As System.Windows.Style
        Dim style As New Style(GetType(GridViewCell))
        Dim cell As GridViewCell = container
        Dim p As Person = item
 
        If p.Age > 18 Then
            If Application.Current.Resources.Contains("CMN_OrangeBackground") Then
                style.Setters.Add(New Setter(GridViewRow.BackgroundProperty, CType(Application.Current.Resources("CMN_OrangeBackground"), Brush)))
            End If
        End If
 
        Return style
    End Function
 
End Class

The style :

<LinearGradientBrush x:Key="CMN_OrangeBackground" EndPoint="0.5,1" StartPoint="0.5,0">
           <GradientStop Color="#FFFFE3C6" />
           <GradientStop Color="#FFFFC082" Offset="0.394" />
           <GradientStop Color="#FFFFC68C" Offset="0.417" />
           <GradientStop Color="#FFFFDB91" Offset="1" />
       </LinearGradientBrush>

All the notify property changed events are raised in properties setters (on in each person property, and one in the MyListOfPersons property).

So if you try this, you will see some cells with an orange color and others without.
But, if you change the age of a person directly into the radgridview, and validate your row change by typing on enter key, you will see that the style selector is not called.

Thanks
Regards

Steeve
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 09 Sep 2010, 01:20 PM
Hi,

No solution ?!

Thanks
0
Pavel Pavlov
Telerik team
answered on 13 Sep 2010, 01:41 PM
Hello LE DREAU Steeve,

Please excuse me for the delayed answer. Your query provoked a small discussion in the team ,

Here is the situation in general :
The current implementation of RadGridView will not call the style selector on changes of the values( even if INotifyPropertyChanged is implemented) .

The behavior is the same as in the MS datagrid and thus might be called "expected behavior" .

Indeed having the RadGridView update the style on property changes is reasonable expectation . We were thinking to implement this in RadGridView. However  we found this would imply significant performance problems. Therefore we have decided not yet to implement  it.

As a workaround I may suggest to call the  RadGridView.Rebind() method after the value has been changed . This should force regeneration of the UI and the style will be applied.


Best wishes,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
LE DREAU Steeve
Top achievements
Rank 1
answered on 13 Sep 2010, 02:46 PM
Hi,

Thanks for you reply. I'm sad to read that there is no solution for this problem.
I'll try to do like you told me.

Thanks
Regards

Steeve
0
Dan Kane
Top achievements
Rank 1
answered on 21 Sep 2010, 07:00 AM
I have also had this same issue, but calling Rebind had a lot of unwanted side effects.

In my case I wanted to refresh the whole column's cells' styles so I used the following after editing a cell's contents which worked perfectly:
foreach (var item in ParametersGridView.Items)
                {
                    var row = ParametersGridView.ItemContainerGenerator.ContainerFromItem(item) as GridViewRow;
                    if (row != null)
                    {
                        var otherCell = row.Cells.FirstOrDefault(x => x.Column == column) as GridViewCell;
                        if (otherCell != null)
                        {
                            otherCell.Style = cell.Column.CellStyleSelector.SelectStyle(otherCell.ParentRow.Item, otherCell);
                            otherCell.Content = column.CreateCellElement(otherCell, row.Item);
                        }
                    }
                }

Might be useful to do something like this in your case...
0
Jonx
Top achievements
Rank 2
answered on 24 Nov 2010, 05:28 PM
Hello guys,
I had the same issue see here:
http://www.telerik.com/community/forums/silverlight/gridview/styleselector-does-not-get-called-gridrow-updated.aspx

The problems have been solved in Q3 the selector is working like a charm for me, even when the bound data is updated from outside the grid. Perfect.

John.
0
Stephen
Top achievements
Rank 1
answered on 17 May 2012, 03:52 AM
Hi, was this ever resolved any further?  I am using the 2012 Quarter 1 cell style selector, and it doesn't refresh at all after initial load.
Tags
GridView
Asked by
LE DREAU Steeve
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
LE DREAU Steeve
Top achievements
Rank 1
Dan Kane
Top achievements
Rank 1
Jonx
Top achievements
Rank 2
Stephen
Top achievements
Rank 1
Share this question
or