c++builderc++builder-6

C++ Builder TStringGrid row colors


The TStringGrid component I'm using in a C++ Builder project seems to alternate row colors by defaults. Even rows have a gray background while odd rows have a white background. How can I disable this alternate coloring so that all rows have the same background color?

Here's what it looks like:

enter image description here

And here is the corresponding entry in the DFM:

  object StringGrid1: TStringGrid [0]
    Left = 0
    Top = 0
    Width = 744
    Height = 300
    Align = alClient
    FixedCols = 0
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    Options = [goFixedHorzLine, goVertLine, goHorzLine, goColSizing, goRowSelect]
    ParentFont = False
    TabOrder = 0
    OnSelectCell = StringGrid1SelectCell
    ColWidths = (
      64
      64
      64
      64
      64)
  end

Solution

  • I don't know which version of VCL you are using, but back in time, when I had been using great and very useful TStringGrid component, I did exactly the same thing, related to custom coloring cells, as you want to do. It is change related to behavior, not defined as property, I think. You need to:

    overload TStringGrid's virtual function for drawing cells in your particular derived class from TStringGrid

    or,

    on your TForm instance containing TStringGrid you want to modify, change behaviour of that particular TStringGrid.

    So, basically you have choice, to make new class derived from TStringGrid and change behavior by overriding function for cell drawing, or to change existing, particular instance of TStringGrid by overriding just that grid's behavior with a help of great ObjectInspector, if it is still called like that.

    It is better of course, to make new class and derive it from TStringGrid, and use it on Form(Parent container) directly which you can reuse later, whenever you want, but it contains some additional work. Maybe, as start point, it is better to change behavior of particular TStringGrid instance you already dropped on ParetContainer(probably TForm) with using object inspector. If these directions are not enough for you, I can place here, some code samples that will be more helpful for you.