ReadOnly cell Background color

8 posts, 0 answers
  1. Ganesh
    Ganesh avatar
    2 posts
    Member since:
    Apr 2016

    Posted 19 Apr Link to this post

    Hi,

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

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 19 Apr Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ganesh
    Ganesh avatar
    2 posts
    Member since:
    Apr 2016

    Posted 19 Apr in reply to Dilyan Traykov Link to this post

    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.

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 21 Apr Link to this post

    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.
  6. Ganesh
    Ganesh avatar
    2 posts
    Member since:
    Mar 2016

    Posted 22 Apr Link to this post

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

  7. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 26 Apr Link to this post

    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.
  8. Ganesh
    Ganesh avatar
    2 posts
    Member since:
    Mar 2016

    Posted 26 Apr in reply to Dilyan Traykov Link to this post

    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.

  9. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 27 Apr Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready