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

Selection on ConditionalFormattingObject

1 Answer 186 Views
GridView
This is a migrated thread and some comments may be shown as answers.
konrad
Top achievements
Rank 1
konrad asked on 22 Sep 2016, 11:43 AM

Hi, 

I am using ConditionalFormattingObject to format cells like this:

 

var x = new ConditionalFormattingObject("column", ConditionTypes.NotEqual, "-1", "", false);
x.CellBackColor = Color.FromArgb(222, 253, 219);
x.CellForeColor = Color.Blue;
column.ConditionalFormattingObjectList.Add(x);

Everything is fine until a multi-cell selection.

It seems to me that ConditionalFormattingObject also overrides the background coloring for the selected cells, but it should not.

Please check the attachment, which shows what is now and what should be.

I do not want to use the ViewCellFormatting event becouse of performance reasons.

 

ConditionalFormattingObject x1 = new ConditionalFormattingObject(column.FieldName, ConditionTypes.NotEqual, "-1"""false);
x1.CellBackColor = Color.FromArgb(222, 253, 219);
x1.CellForeColor = Color.Blue;
column.ConditionalFormattingObjectList.Add(x1);
ConditionalFormattingObject x1 = new ConditionalFormattingObject(column.FieldName, ConditionTypes.NotEqual, "-1"""false);
x1.CellBackColor = Color.FromArgb(222, 253, 219);
x1.CellForeColor = Color.Blue;
column.ConditionalFormattingObjectList.Add(x1);

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Sep 2016, 09:26 AM
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 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.
Tags
GridView
Asked by
konrad
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or