Hello Dominik,
Thank you for writing.
The selected cells style comes from the applied theme. However, note that the conditional formatting or the style applied in the
CellFormatting event have higher priority than the theme. That is why the selected color from the theme is overridden. In order to format the cells according to some condition and keep the hot tracking color, the possible solution is to override the theme settings at run time by using the
CellFormatting event. Additional information about the existing API is explained in the following help article:
http://docs.telerik.com/devtools/winforms/telerik-presentation-framework/override-theme-settings-at-run-time
The code snippet below demonstrates a
sample approach how to customize the cells for the default state and when the column is current:
private
void
radGridView1_CellFormatting(
object
sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
if
(e.Row
is
GridViewDataRowInfo)
{
if
(e.Column.Name ==
"Country"
&& e.CellElement.Value.ToString().Contains(
"France"
))
{
e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Red,
""
);
e.CellElement.SetThemeValueOverride(LightVisualElement.DrawFillProperty,
true
,
""
);
e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid,
""
);
e.CellElement.SetThemeValueOverride(LightVisualElement.BackColorProperty, Color.Red,
"GridDataCellElement.IsCurrentColumn"
);
e.CellElement.SetThemeValueOverride(LightVisualElement.DrawFillProperty,
true
,
"GridDataCellElement.IsCurrentColumn"
);
e.CellElement.SetThemeValueOverride(LightVisualElement.GradientStyleProperty, GradientStyles.Solid,
"GridDataCellElement.IsCurrentColumn"
);
}
else
{
e.CellElement.ResetThemeValueOverride(LightVisualElement.BackColorProperty,
""
);
e.CellElement.ResetThemeValueOverride(LightVisualElement.DrawFillProperty,
""
);
e.CellElement.ResetThemeValueOverride(LightVisualElement.GradientStyleProperty,
""
);
e.CellElement.ResetThemeValueOverride(LightVisualElement.BackColorProperty,
"GridDataCellElement.IsCurrentColumn"
);
e.CellElement.ResetThemeValueOverride(LightVisualElement.DrawFillProperty,
"GridDataCellElement.IsCurrentColumn"
);
e.CellElement.ResetThemeValueOverride(LightVisualElement.GradientStyleProperty,
"GridDataCellElement.IsCurrentColumn"
);
}
}
}
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this
blog post and share your thoughts.