OwnerDrawCell changing background colors for styles not the row and column

Originally Posted 15 July 2017, 6:36 pm EST

  • Originally Posted 15 July 2017, 6:36 pm EST

    In versions prior to the latest 4.0.20172.271 this was working properly. I have a number of forms and flexgrid controls in my program. All have the same settings for Visual Style and the options for Normal, Focus and other various styles. All Flexgrid controls that do not have an OwnerDrawCell routine continue to work properly. The flexgrid controls that have an OwnerDrawCell do not work the way that they used to. The code in the OwnerDrawCell is used to change the background color for one cell in the Grid based on information in the data. Here is the code used to change the Background color.

    If C1FlexGridItems.Cols(e.Col).Name = "Packs" And e.Row > 1 Then
    If C1FlexGridItems.GetData(e.Row, "BreakableCa") = "Y" Then
    e.Style.BackColor = Color.LightGreen
    Else
    e.Style.BackColor = Color.White
    End If
    End If

    The background for the Focus row is changed to the Light Green or White as well as the background of the cell.

    This was working for all versions in 2016 and 20171.248. I just upgraded to 4.0.20172.271 and the background for the Focus of a Row is not using the Focus Style specified in the FlexGrid specifications, but is being changed to the Light Green or White based on the information form the data.

    Is there a change required in the new version to retain the colors for the Focus style and only change the background color for an individual cell.

    Thanks in advance for your help.
    Don Becker
  • Reply

    Update: The code does change the background of the column as desired. The issue is that it also changes the Background of the Highlight Style as well. The SelectionMode of the FlexGrid controls are set to Row. The VisualStyle is set to Office2010Black. The standard background for the Hightlight Style is a blue color. This will Highlight the selected row to have a background of Blue for the entire row except the column selected. For all of the FlexGrid controls that have the above code, the Background color for the Highlighted Row will be either Green or White based on the data in the one column. I copied all of the backup files for version 4.0.20171.248 back to the ComponentOne bin folder and reset the References and now I can publish the updated program. Please, let me know when this issue has been resolved in a later version or how to make sure that I do not change he background color for the Highlight Style while changing the background color of an individual cell.

    For now, I have to stay on version 4.0.20171.248 of the WinForms .Net 4.0 to make sure that the program displays consistently.
  • Reply

    Hi,

    1. There has been observed no such difference in behaviours among 4.0.20172.271 and its previous builds. Could you kindly share a stripped-down sample so that I can replicate the said behaviour at my end, and inform the developers (if needed).

    2. In order to change background colour for a cell only, you can add a new CellStyle to C1FlexGrid's styles and set its BackColor to LightGreen.
    Dim cs1 As CellStyle
    cs1 = C1FlexGrid1.Styles.Add("CS1")
    cs1.BackColor = Color.LightGreen


    Then, in OwnerDrawCell event, you can use SetCellStyle method to assign this style to the cell, if the condition satisfies.
    If *condition* Then
    C1FlexGrid1.SetCellStyle(e.Row, e.Col, cs1)


    Attached is the sample for your reference. Hope this helps.

    Regards,
    Meenakshi
    2017/07/Prj_StyleAfterOwnerDrawCell.zip
  • Marked as Answer

    Reply

    Changing to the suggested method resolved the issue. Thanks for your assistance.
Need extra support?

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

Learn More

Forum Channels