How to let cells in StringGrid have different backgound color? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to let cells in StringGrid have different backgound color?

For example, some column have yellow and the other keep being white. Use different backgound to indicate different data areas.
Is there any way to do it?
Thank you!

Comments

  • zibadianzibadian Posts: 6,349Member
    : For example, some column have yellow and the other keep being white. Use different backgound to indicate different data areas.
    : Is there any way to do it?
    : Thank you!
    :
    In the OnDrawCell you first draw a rectangle with the color you want. If you pass the Rect parameter as its size, the entire cell will be that color. The you draw the foreground, which will be drawn over the rectangle, like in an oil-painting.
  • earth_walkerearth_walker Posts: 184Member
    Hi! Is this method same as: In the DrawCell event, first draw the retangle to cover the cell, then use "TextRect" fucntion to put the string on?
    In this way I can implement the cell with static string, but just feel it is not easy to implement some field which have changing data, or some field which can be edited by user.
    Is there way to make editable cells to have different background?
    Thank you!
  • zibadianzibadian Posts: 6,349Member
    : Hi! Is this method same as: In the DrawCell event, first draw the retangle to cover the cell, then use "TextRect" fucntion to put the string on?
    : In this way I can implement the cell with static string, but just feel it is not easy to implement some field which have changing data, or some field which can be edited by user.
    : Is there way to make editable cells to have different background?
    : Thank you!
    :
    I think, the background will turn white while the user is editing the text. After he's done editing, it will turn back to the supplied background color. If you want to have a new background color during the edit, you'll probably need to alter the grid editor object, but I cannot provide you with help on that.
  • earth_walkerearth_walker Posts: 184Member
    Understand. Thank you!

Sign In or Register to comment.