I have implemented a StyleSelector that applies a style based on a data condition for the ItemSource.
However this only works when a new record is inserted into the grid which seems to call the RowLoaded event.
I want to be able to apply a style to a row based on this ItemSource data value when a row is edited. Our DataContext.Load method is calling LoadBehaviour.MergeIntoCurrent for both inserted and updated records. Only the Inserted records seem to run the StyleSelector.
So does anyone know how to select an individual row in a grid and apply a style to it - even if no grid event has fired. In our system some other Composite event in our UI fires instead - and we have the Id of the record - but no reference to the Grid row.
Or does someone know how to get the StyleSelector to work when a bound value in a row has been changed externally by another view. We have 2 views bound to the same RIA services domain context. One view contains a GridView which is bound to DomainContext.A and the other view contains a detail view which is bound to the same DomainContext.A. The detail view updates a record in DomainContext.A and the changes are reflected in the grid - but the StyleSelector does not get called.
10 Answers, 1 is accepted
You may take a look at this forum thread for a reference.
the Telerik team
I have the same problem but the thread you recommend does not help...
Or I'm unable to make it work...
They are several other thread requesting a solution for that problem and none has a usable solution.
StyleSelector does only work for new rows and when I use virtualisation the style seems to be applied randomly.
I guess because it depends where the existing row gets reused in the virtualisation...
Also calling rebind is not an option because it is slow and because it does flicker once when everything is rebuilt.
Would you be kind enought and provide a working demo on how to change the style of a row based of the row cells content?
The style should also update if the bound underlying data changes.
Here is a scenario I try to implement...
I have a small grid that displays a list of adresses. The grid has an external DetailsPresenter to display the full details of the selected address. The addresses can be disabled throught an IsActive property. That property is visible in a check box column in the grid but also as a check box in the DetailsPresenter.
What I want is that when I uncheck the box in the grid, the row background changes to grey. I also want the row background turn to grey when I uncheck the check box in the related presenter. As both controls are bound to the IsActive property this should not be a problem. Of course, virtualisation should be on as without my grid is too slow...
So... would you please show me an example of how this can be achieved?
That would be really nice,
Thanks a lot in advance,
What is the version of RadGridView that you are using ? Did you try it out with our official Q3 2010 release ?
the Telerik team
And then indeed, your StyleSelector is working... It's even working when you update the bound data: perfect. Thanks a lot exactly what I needed.
Here is what I have...
But then I allso tried to make it work by code... I have the following. It is working at row creation and row edit... but now when I update the underlying data. Which event should I handle to update the row when the bound data changes? This is just out of curiosity as the styleselector stuff is working as expected on Q3...
Thanks a lot for your help,
The StyleSelector is called upon changing the value of the particular property. Consequently, neither RowLoaded (that is fired only when a row is loaded) and RowEditEnded (that is fired after the items has been edited) are proper in this case.
Still, I am glad that your issue has been resolved.
All the best,
the Telerik team
So StyleSelector is the way to go. No problem, it's working great.
One last question: how can I get the default row style and apply it to my row before modifying it to suit my needs?
Thank you for your help... It helped a lot...
However, I did find a minor issue. It seems that the style selection only happens if the property change event is on base list type that is bound to the grid. They do NOT get called if the property change is on another related object.
For example, if you have 2 entities: Employee and Department, and you are displaying a grid of employee information, you might have two columns defined as follows (using the navigation properties on Employee).
It appears that the style selectors will not get called in this circumstance if the "Name" property on department changes even though it is bound to a column.
In my particular situation I just worked around it by raising an innocuous property change event on the parent object when something in the child changes, but I thought someone might want to know. Should I enter a bug on this, or was this by design?
Indeed, you are quite correct. We have logged the issue in our Public Issue Tracking System and you may follow its progress here.
Thank you for the cooperation. I have updated your Telerik points accordingly.
the Telerik team