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

9 posts, 0 answers
  1. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 07 Sep 2010 Link to this post

    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
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 07 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 08 Sep 2010 Link to this post

    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
  5. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 09 Sep 2010 Link to this post

    Hi,

    No solution ?!

    Thanks
  6. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 13 Sep 2010 Link to this post

    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
  7. LE DREAU Steeve
    LE DREAU Steeve avatar
    74 posts
    Member since:
    Aug 2012

    Posted 13 Sep 2010 Link to this post

    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
  8. Dan Kane
    Dan Kane avatar
    8 posts
    Member since:
    Mar 2010

    Posted 21 Sep 2010 Link to this post

    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...
  9. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 24 Nov 2010 Link to this post

    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.
  10. Stephen
    Stephen avatar
    1 posts
    Member since:
    Jul 2012

    Posted 16 May 2012 Link to this post

    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.
Back to Top
DevCraft banner