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

Cell color & RowLoaded problem

5 Answers 104 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jean Ressouche
Top achievements
Rank 1
Jean Ressouche asked on 08 Jan 2011, 05:07 PM
Dear Telerik Team,

I have a little issue with the RowLoaded function of the RadGridView :
i use this event to set a binding on a cell, in order to change for example the Background color. 

private void GvRowLoaded(object sender, RowLoadedEventArgs e)
{
    foreach (var gc in e.Row.Cells.Where(gc => gc.Column.UniqueName == "Status"))
        {
            gc.SetBinding(BackgroundProperty, new Binding("Status") { Converter = new StatusToColorConv() });
        }
}
This is working pretty well but, if the targeted column is not visible when the event is raised, 
e.Row.Cells doesn't contain it, and even if i scroll to see the column, the event is not re-fired (normal but not convenient).


How should i proceed ?


Note that i search a code related solution, not a xaml solution (like a CellTemplate).


Thanks in advance :)

5 Answers, 1 is accepted

Sort by
0
Accepted
Vanya Pavlova
Telerik team
answered on 10 Jan 2011, 02:33 PM
Hi Jean,

 
If you are looking for programmatic approach to apply some changes upon changing the value of particular property I believe that CellStyleSelectors are much more appropriate in this case, please refer to the following blog post and online demo:

                          "Conditional styles and templates with RadGridView for Silverlight and WPF"
                                                                 CellStyleSelectors

All the best,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
MiroslavStantic
Top achievements
Rank 1
answered on 21 Mar 2011, 04:00 PM
What if I really need to do it using a RowLoaded event, or similar "code-behind" concept? Is there no way of doing this when the row is created and loaded with data? I don't want to have to add any code in XAML. I already have an attached property defined on the grid which links the necessary code to the RowLoaded event.

I was using RowLoaded, but recently noticed it doesn't perform well. For example, according to some rule, it changes the background color of the first row, and if you scroll down, that first row goes up, out of view, and a row with different data appears at the bottom, but has the same backround color. How hard would it be for you to create a RowLoaded event which doesn't "break" like this when virtualization is on. (I only suspect that this issue has something to do with that, I'm not sure.)
0
Vlad
Telerik team
answered on 21 Mar 2011, 04:07 PM
Hi,

 You do not have to use XAML to work with StyleSelectors - the approach will work for both XAML (MVVM) and code. 

Regards,
Vlad
the Telerik team
0
MiroslavStantic
Top achievements
Rank 1
answered on 21 Mar 2011, 05:06 PM
I'm currently working on something that requires more control and flexibility. Implementing it as a style selector is probably doable.

I am working on a separate component, which resembles a rule engine. I wanted to apply rules to grids using an attached property. The changes to existing code are this way minimal. The only thing required is to define the attached property and the rule engine applies the appropriate rules to the grid.

One issue is that some grids already have style selectors. They will probably be transformed into rules applied through the rule engine, so they aren't a problem. But what if there was a piece of code that I didn't want to put into the rule, something I wanted to keep in code. I imagine I would create a style selector, but not inheriting from StyleSelector base class, but from a new RuleStyleSelector class that I write. There would probably be some control over which code has priority: the custom code or the rule.

Having to apply a style selector in code feels too "fixed". I had hoped to keep this separate from other style-related code.
0
MiroslavStantic
Top achievements
Rank 1
answered on 22 Mar 2011, 06:25 PM
It wasn't as difficult as I thought it would be. I apply the row style selector using the attached property.
I'll wait and see if I have to deal with the case when a rowstyleselector is already set on the grid, because it's possible they will all be converted into rules anyway.
Tags
GridView
Asked by
Jean Ressouche
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
MiroslavStantic
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or