Applying theme to C1FlexGrid: WordWrap/TextAlign are reset

Posted by: wknauf on 12 October 2021, 11:06 pm EST

  • Posted 12 October 2021, 11:06 pm EST - Updated 3 October 2022, 1:40 pm EST

    Hi C1,

    when applying a theme to C1FlexGrid, some style properties like “WordWrap” or “TextAlign” are reset, though the are not defined in the theme.

    See attached sample: click the button and you will see that those two properties are reset.

    FlexTheme.zip

    This probably also applies for all other properties that are undefined in the theme (e.g. “ImageAlign”), but I did not check it.

    This is the theme “Office2010Silver” in C1ThemeDesigner:

    Is this a bug?

    Sounds like https://www.grapecity.com/forums/winforms-edition/flexgrid-and-themes_1 (which was never resolved)

    Currently, my workaround is to implement “IC1Themeable” and reset the properties in “OnThemeChanged”.

    Best regards

    Wolfgang

  • Posted 13 October 2021, 3:53 pm EST

    Hello,

    Thank you for reporting this.

    We have forwarded this to the development team for investigation and will let you know as soon as we get the update from the developers’ end.

    [Internal Tracking Id: C1WIN-25872]

    Regards,

    Prabhat Sharma.

  • Posted 18 October 2021, 12:25 am EST

    Yes, I can confirm now that also “ImageAlign” is reset.

  • Posted 9 February 2022, 1:06 am EST

    Hi C1,

    any updates on this?

    Best regards

    Wolfgang

  • Posted 9 February 2022, 1:39 pm EST

    Hello Wolfgang,

    As per the developers, this was originally designed that way: when applying a theme, the style properties are reset to their default values (based on the current VisualStyle), regardless of whether they were set by the user or not. And we cannot change this behavior at the moment, without a complete reworking of all styles that we can’t afford at the moment.

    The workaround indicated in the description is the correct solution. This approach is best used in cases where the number of columns and fixed rows may change.

    In addition, you can also use custom styles, as well as column properties (TextAlign, ImageAlign) using this logic: custom styles override build-in styles, column properties override custom styles.

    This can be done both at design time and at run-time (in code). The implementation of this sample, in this case, will look like this:

    // once during FlexGrid initialization
    
    // create custom style with the right properties
    var style = c1FlexGrid1.Styles.Add("CustomCellStyle");
    style.WordWrap = true;
    style.TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter; 
    
    // set custom style for all columns except fixed (works with themes)
    // the custom style will be merged with the built-in style, 
    // but WordWrap and TextAlign property will be overrided by the custom style.
    for (int i = c1FlexGrid1.Cols.Fixed; i < c1FlexGrid1.Cols.Count; i++)
     c1FlexGrid1.Cols[i].Style = style;
    
    // set TextAlign for fixed columns,
    // this value will be used regardless of styles and theme
    for (int i= 0; i < c1FlexGrid1.Cols.Fixed; i++)
       c1FlexGrid1.Cols[i].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.LeftTop; 
    
    // set TextAlign for fixed rows,
    // this value will be used regardless of styles and theme
    for (int i = 0; i < c1FlexGrid1.Rows.Fixed; i++)
       c1FlexGrid1.Rows[i].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.LeftTop; 
    

    the same can be done at design time using Column and Styles editor forms. This approach is best used in cases where the number of columns and fixed rows is constant.

    Regards,

    Prabhat Sharma.

  • Posted 10 February 2022, 11:50 pm EST

    Hi Prabhat,

    too bad this cannot be changed on your side - I think others might be hit by this issue, too.

    But for our application, I found a centralized workaround so that I can reset differing property values to their original values after applying themes.

    Best regards

    Wolfgang

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels