Why "e.RowElement.BackColor = Color.Black; "doesn't work?

5 posts, 1 answers
  1. özer
    özer avatar
    33 posts
    Member since:
    Jun 2020

    Posted 19 Feb Link to this post

    Hi: 

    I am having an issue with "changing the selected line color", which was replied earlier in the forums.
    I am doing the same as explained here, but the background color does not change while the text of the line changes.

    private void rgvCompanyList_ViewRowFormatting(object sender, RowFormattingEventArgs e)
            {
                if (e.RowElement.IsSelected && e.RowElement.IsCurrent)
                {
                    
                    e.RowElement.DrawFill = true;
                    e.RowElement.GradientStyle = GradientStyles.Solid;
                    e.RowElement.BackColor = Color.Black; // It doesn't work !
                    e.RowElement.ForeColor = Color.White; // It works
                    // e.RowElement.NumberOfColors = 1; that didn't work either 
                }
                else
                {
                    e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
                    e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
                    // e.RowElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
                }
            }

  2. Nadya
    Admin
    Nadya avatar
    508 posts

    Posted 19 Feb Link to this post

    Hello, özer,

    Note that the look of our controls is defined through themes. Since different themes have different design, look and feel the applied theme settings may differ as well. In some themes the row color is applied on a row level while in other themes it is on cell level. This is why it is important to use the right cell/row formatting event for the specific case that you have. According to the provided information it is not clear which is the specific theme that you use in your application and which you would like to customize. Can you please specify it so I can assist you further with applying a custom color for the selected row.

    I am looking forward to your reply.

    Regards,
    Nadya
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  3. özer
    özer avatar
    33 posts
    Member since:
    Jun 2020

    Posted 19 Feb in reply to Nadya Link to this post

    Hello Nadia

    I have four theme options in my application.
    Breeze
    Aqua
    Desert
    TelerikMetroBlue
    I checked again and noticed that my code only works for aqua theme.
    Are there any methods that work for all themes? Or how do I make the line color different from the selected line color? Because in some themes, the row color and the selected row color are the same.

     

     

  4. Answer
    Nadya
    Admin
    Nadya avatar
    508 posts

    Posted 22 Feb Link to this post

    Hello, özer,

    Thank you for specifying which are the themes that you use.

    The code snippet provided here works for the Aqua theme:

    private void RadGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
    {
        if (e.RowElement.IsSelected && e.RowElement.IsCurrent)
        {
           
            e.RowElement.DrawFill = true;
            e.RowElement.GradientStyle = GradientStyles.Solid;
            e.RowElement.BackColor = Color.Black; // It doesn't work !
            e.RowElement.ForeColor = Color.White; // It works
            // e.RowElement.NumberOfColors = 1; that didn't work either 
        }
        else
        {
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
            // e.RowElement.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
        }
    }
    

    For the rest of the themes - TelerikMetroBlue, Desert, and Breeze theme there is defined additional color for the selected CellElement. This is why you should use the following code in the CellFormatting event in additiona to apply the proper formatting for this cell:

     private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
     {
         if (e.Row.IsSelected && e.CellElement.IsCurrent)
         {
    
             e.CellElement.DrawFill = true;
             e.CellElement.GradientStyle = GradientStyles.Solid;
             e.CellElement.BackColor = Color.Black;
             e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
             e.CellElement.BorderLeftColor = Color.White;
             e.CellElement.BorderRightColor = Color.White;
         }
         else
         {
             e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
             e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
             e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
             e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
             e.CellElement.ResetValue(LightVisualElement.BorderRightColorProperty, ValueResetFlags.Local);
             e.CellElement.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local);
         }
     }
    
    
    • TelerikMetroBlue theme:

    • Desert theme:

    • Breeze theme:

    I hope this helps. Let me know if you have any other questions.

    Regards,
    Nadya
    Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

  5. özer
    özer avatar
    33 posts
    Member since:
    Jun 2020

    Posted 24 Feb in reply to Nadya Link to this post

    Yes, this is exactly the answer I was looking for. Thanks Nadya.
Back to Top