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

ReadOnly cell Background color

7 Answers 417 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ganesh
Top achievements
Rank 1
Ganesh asked on 19 Apr 2016, 09:29 AM

Hi,

How to change the background color of readonly rows of RadGridView?

7 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 19 Apr 2016, 11:21 AM
Hello Ganesh,

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
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Ganesh
Top achievements
Rank 1
answered on 19 Apr 2016, 11:33 AM

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.

0
Dilyan Traykov
Telerik team
answered on 21 Apr 2016, 12:00 PM
Hello Ganes,

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
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Ganesh
Top achievements
Rank 1
answered on 22 Apr 2016, 11:46 AM

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);

0
Dilyan Traykov
Telerik team
answered on 26 Apr 2016, 11:29 AM
Hello Ganesh,

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
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Ganesh
Top achievements
Rank 1
answered on 26 Apr 2016, 11:34 AM

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.

0
Dilyan Traykov
Telerik team
answered on 27 Apr 2016, 12:58 PM
Hello Ganesh,

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
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Ganesh
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Ganesh
Top achievements
Rank 1
Ganesh
Top achievements
Rank 1
Share this question
or