Applying Theme to C1FlexGrid resets CellStyle.DataMap

Posted by: wknauf on 14 November 2023, 8:23 pm EST

    • Post Options:
    • Link

    Posted 14 November 2023, 8:23 pm EST

    Hi C1,

    see attached sample: it creates several cell styles with a DataMap. Later, a theme is applied to the form. The result is that the DataMaps in styles are reset.

    FlexDataMapReset.zip

    I think I reported similar problems for other CellStyle properties earlier, and some were fixed. This is hopefully the last of this kind ;-).

    Best regards

    Wolfgang

  • Posted 15 November 2023, 7:30 pm EST

    Hello Wolfgang,

    Thank you for bringing this matter to our attention and for the sample.

    We were able to replicate the behavior at our end, so we have escalated to the development team to get their insights on this behavior. We will give you an update as soon as we get any necessary information.

    However, until then, you can merge your custom style with a new style for the column and the cell created using the StyleNew property of Column and CellRange as follows:

    CellStyle style = this.c1FlexGrid1.Styles.Add("StyleDataMap", this.c1FlexGrid1.Styles.Normal);
    style.DataMap = dataMap;
    //this.c1FlexGrid1.Cols[1].Style = style;
    var newStyle = this.c1FlexGrid1.Cols[1].StyleNew;
    newStyle.MergeWith(style);
    
    
    for (int row = this.c1FlexGrid1.Rows.Fixed; row < this.c1FlexGrid1.Rows.Count; row++)
    {
        //Create Style for each cell:
        CellStyle styleCell = this.c1FlexGrid1.Styles.Add("StyleDataMap_Row" + row, this.c1FlexGrid1.Styles.Normal);
        styleCell.DataMap = dataMap;
        //this.c1FlexGrid1.SetCellStyle(row, 2, styleCell);
        var cellRange = c1FlexGrid1.GetCellRange(row, 2);
        var newCellStyle = cellRange.StyleNew;
        newCellStyle.MergeWith(styleCell);
    }

    Please refer to the attached sample for implementation.

    [Internal Tracking ID: C1WIN-31390]

    Regards,

    Prabhat Sharma.

    FlexDataMapReset.zip

  • Posted 16 November 2023, 7:20 am EST

    Thanks! But I already worked around it by storing the DataMaps before applying to theme and restoring them afterwards.

    I noticed that the “StyleNew” property creates a new style that is not added to the C1FlexGrid styles collection, thus the style is not under C1FlexGrid control. This is probably the reason why it is not affected by the theme change. I can reproduce it by setting BackColor in my custom CellStyle before calling “NewStyle”. Now, the back color is not overwritten by the theme. If I set the BackColor without “NewStyle”, it is replaced.

    Is this behavior intentional or some kind of bug? If it is the expected behavior, this might be an interesting workaround for the problem that the theme overwrites style properties. But I have the impression that it is not expected ;-).

    Best regards

    Wolfgang

  • Posted 16 November 2023, 4:21 pm EST

    Hello Wolfgang,

    We initiated a query for this behavior with developers, and they also think that the behavior is not expected and might be a bug.

    Thank you for reporting this to us. We will notify you as soon as this issue is fixed.

    Regards,

    Prabhat Sharma.

  • Posted 13 March 2024, 7:14 pm EST

    Hello Wolfgang,

    We are glad to inform you that the issue has been resolved in the 2023v3 HF2 builds.

    Please upgrade to the latest version to fix this issue.

    Regards,

    Prabhat Sharma.

  • Posted 14 March 2024, 7:08 am EST

    I can confirm that my initial issue (applying a theme resets the “DataMap” property) is fixed.

    What about the followup question? You suggested a workaround involving the “StyleNew” property, and my feedback was that the workaround only worked because the new style was not added to the “Styles” collection. “StyleNew” seems to create a style that is not managed by the grid and thus was not affected by the issue. Is this the expected behavior? Did the developers on this?

    I am not affected by this question, because I never used “StyleNew”.

    Best regards

    Wolfgang

  • Posted 14 March 2024, 8:59 pm EST - Updated 14 March 2024, 10:11 pm EST

    Hello Wolfgang,

    “Styles” collection in FlexGrid is used to store references to custom CellStyles and some pre-defined styles that can be accessed and used later on.

    On the other hand, the "StyleNew” property is used to get the existing style or create a new style for a RowCol and does not concern cell styles present in the “Styles” collection.

    Regards,

    Uttkarsh.

  • Posted 15 March 2024, 1:09 am EST

    OK, thanks!

    Wolfgang

  • Posted 23 March 2024, 10:21 pm EST

Need extra support?

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

Learn More

Forum Channels