Changing the fore color of flexgrid rows highlight

Posted by: maximusdebois on 8 February 2022, 11:57 pm EST

  • Posted 8 February 2022, 11:57 pm EST

    I am using flexgrid with about 1000 rows and I have set the row highlight color to light blue. I want to change the fore color of the rows when a column equals to "Faulty" or "Obsolete". Am able to do that using owner draw event but problem is the flexgrid becomes very slow.
    Am using this code in the owner draw:

    foreach (Row r in photomaticGrid.Rows)
    if (r[13].ToString().Equals("Faulty") && e.Row == r.Index &&
    e.Col != 1 && e.Row > 0)
    CellStyle nc = photomaticGrid.Styles.Add("Faulty");
    nc.ForeColor = Color.FromArgb(137, 70, 166);
    e.Style = nc;
    if (r[13].ToString().Equals("Obsolete") && e.Row == r.Index &&
    e.Col != 1 && e.Row > 0)
    CellStyle nc = photomaticGrid.Styles.Add("Obsolete");
    nc.ForeColor = Color.FromArgb(206, 18, 18);
    e.Style = nc;
  • Marked as Answer

    Replied 9 February 2022, 6:38 pm EST


    the problem is that you loop over the whole grid each time the "OwnerDrawCell" event is called. You should apply the style only for the current row ("e.Row").

    You could also apply the CellStyle after filling the grid and thus avoid owner draw completely.

    Best regards

  • Replied 9 February 2022, 9:44 pm EST


    The OwnerDrawCell event is fired for a cell whenever it is painted in the grid and you are iterating through all the rows of the grid in the event to set the styles. So on each call of the event, you iterate through 1000 rows making the grid slow down.
    Instead, as suggested by Wolfgang, you should only set the style for the current row. Kindly refer to the attached sample showing the same.

  • Replied 11 February 2022, 6:35 am EST

    Thanks man
Need extra support?

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

Learn More

Forum Channels