Selection on ConditionalFormattingObject

2 posts, 0 answers
  1. Dominik
    Dominik avatar
    59 posts
    Member since:
    Dec 2012

    Posted 22 Sep Link to this post

    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);
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 26 Sep Link to this post

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