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

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

4 Answers 196 Views
GridView
This is a migrated thread and some comments may be shown as answers.
özer
Top achievements
Rank 2
Veteran
Iron
özer asked on 19 Feb 2021, 12:57 PM

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

4 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 19 Feb 2021, 02:34 PM

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/.

0
özer
Top achievements
Rank 2
Veteran
Iron
answered on 19 Feb 2021, 09:22 PM

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.

 

 

0
Accepted
Nadya | Tech Support Engineer
Telerik team
answered on 22 Feb 2021, 04:22 PM

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/.

0
özer
Top achievements
Rank 2
Veteran
Iron
answered on 24 Feb 2021, 04:59 PM
Yes, this is exactly the answer I was looking for. Thanks Nadya.
Tags
GridView
Asked by
özer
Top achievements
Rank 2
Veteran
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
özer
Top achievements
Rank 2
Veteran
Iron
Share this question
or