0

I am creating a diary calendar, I want to be able to change the colour of the cell based on a certain string inside the cell. E.g if TStringGrid.Cells[x,y] = '1' Change the background colour to blue, if TStringGrid.Cells[x,y] = '2' Change the background colour to red, is there a way to do this? And how would I stop the background colour from covering the text in the cell?

Wiliam Cardoso
  • 434
  • 1
  • 8
  • 23
  • Use the `OnDrawColumnCell` event as in the last example of [this answer](https://stackoverflow.com/a/43651615/2292722). Paint the background first, then the text. – Tom Brunberg Mar 15 '19 at 16:57
  • @TomBrunberg Hi tom I've had a go using that, but it doesn't seem like it works when the text isn't in there before the `OnDrawColumnCell` function is called, which makes sense, but how would I got about it, the way I'm doing it, once you click a button, the text is then input into the cell, but it seems to call the `OnDrawColumnCell` before it fills the text. Sorry if the answer is already on the link you showed, I'll have another look through. Thank you – Wiliam Cardoso Mar 18 '19 at 10:10
  • Add `StringGrid1.Repaint;` at the end of the button click handler. – Tom Brunberg Mar 18 '19 at 11:20
  • @TomBrunberg I don't know if this is related or not, but the whole cell isn't being coloured. I didn't know how to add to this comment so uploaded to imgur https://imgur.com/a/KEzNQkI – Wiliam Cardoso Mar 18 '19 at 13:43
  • Look at [this answer](https://stackoverflow.com/a/41856141/2292722) of mine. It appears to answer your issue, but if not, post a new question. – Tom Brunberg Mar 18 '19 at 14:10

0 Answers0