Recent

Author Topic: Coloring a stringgrid cell background(solved)  (Read 433 times)

jbmckim

  • Full Member
  • ***
  • Posts: 139
Coloring a stringgrid cell background(solved)
« on: September 12, 2020, 09:48:38 pm »
I get using OnPrepareCanvas to change cell color.  I do this successfully in a couple places.

What's confusing me is a slightly different requirement.  I need to allow the user to remove an alarm state (stringgrid cell, red background) from a row by pushing a button. (Going cell by cell is fine. The UI requirement is a column but that can be done cell by cell.)

When this happens, there's no change to the cell value per se, just a change to the background.  Therefore, OnPrepareCanvas doesn't fire.  (The problem only occurs on reset as the initial alarm is thrown in response to a new value being added to the cell in question.)

Therefore, how do I change the background color without modifying cell value?
« Last Edit: September 15, 2020, 11:04:49 pm by jbmckim »

wp

  • Hero Member
  • *****
  • Posts: 7727
Re: Coloring a stringgrid cell background
« Reply #1 on: September 12, 2020, 09:51:32 pm »
Call StringGrid.Invalidate to enforce a redraw of the grid; as a consequence of this OnPrepareCanvas will be called for each cell before it is painted.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jbmckim

  • Full Member
  • ***
  • Posts: 139
Re: Coloring a stringgrid cell background
« Reply #2 on: September 15, 2020, 11:04:26 pm »
Outstanding.  Thanks.

 

TinyPortal © 2005-2018