7 Answers, 1 is accepted
You could use either a RowStyleSelector or a CellStyleSelector to achieve the desired effect.
Please also have a look at the "Read-Only Style Selector" demo of our SDK Samples Browser where a similar effect has been demonstrated.
I hope you find this information helpful.
Regards,
Dilyan Traykov
Telerik
Hi,
I have done in the similar way by assiginig new style setter property with required background colour but as the row is readonly, it's background colour remains gray and not changing.
Could you elaborate on the exact approach you've used to set the background?
To help you out, I'm attaching a sample project, showing how you can use a RowStyleSelector to achieve the desired effect. I hope that you find it helpful.
Regards,
Dilyan Traykov
Telerik
This is my code snippet;
public void SetRowBackColor(string color, params int[] rowIndices)
{
var brush = (SolidColorBrush)new BrushConverter().ConvertFromString(color);
var s = new Style();
s.Setters.Add(new Setter(BackgroundProperty, brush));
foreach (var item in rowIndices)
{
var row = (GridViewRow)RadGridView.ItemContainerGenerator.ContainerFromIndex(item);
if (row == null)
{
RadGridView.UpdateLayout();
RadGridView.ScrollIntoView(RadGridView.Items[item]);
row = (GridViewRow)RadGridView.ItemContainerGenerator.ContainerFromIndex(item);
}
row.Style = s;
}
}
And I am setting it as SetRowBackColor("Blue", 0);
Did you manage to have a look at the RowStyleSelector approach I provided in my previous reply and if so could you please specify whether or not it would work in your particular scenario?
Regards,
Dilyan Traykov
Telerik
No. Can you give me a work around with respect to the code snippet I posted earlier in the comments?
As my requirement is that, it will help me.
Generally, working directly with the visual elements is not recommended and you should instead work with the data items when performing such styling logic. As the RadGridView uses UI Virtualization the visual elements, such as rows and cells, are reused and this might lead to undesired behavior.
If you would specify why you need to use this exact approach, maybe I can offer you another solution based on your specific requirements.
Regards,
Dilyan Traykov
Telerik