TRzStringGrid Cell Colour

Viewing 2 reply threads
  • Author
    Posts
    • #1257
      Barry Wood
      Participant

        Hi,

        Usually when I want to colour the selected cell I would use StringGrid1.SelectedColor:= clBlue, for example.

        This doesn’t work with the Raize version. Can you advise how that would happen?

      • #1258
        Ray Konopka
        Keymaster

          Hi Barry,

          The TStringGrid component does not have a SelectedColor property. And since the TRzStringGrid is a direct descendant of the TStringGrid, that property is not inherited to the TRzStringGrid either because it doesn’t exist. Perhaps you were using a different grid control.

          Regardless, to customize the coloring of the grid cells, you can use the OnDrawCell event handler. For example, the code below shows a very basic way to change the selection color.

          Hope this helps,
          Ray

          procedure TForm7.FormCreate(Sender: TObject);
          begin
            RzStringGrid1.Cells[ 1, 1 ] := 'Delphi 10 Seattle';
            RzStringGrid1.Cells[ 1, 2 ] := 'Delphi 10.1 Berlin';
            RzStringGrid1.Cells[ 1, 3 ] := 'Delphi 10.2 Tokyo';
            RzStringGrid1.Cells[ 1, 4 ] := 'Delphi 10.3 Rio';
          end;
          
          procedure TForm7.RzStringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
          begin
            if gdSelected in State then
            begin
              RzStringGrid1.Canvas.Brush.Color := clGreen;
              RzStringGrid1.Canvas.Font.Color := clWhite;
            end
            else
            begin
              RzStringGrid1.Canvas.Brush.Color := clWindow;
              RzStringGrid1.Canvas.Font.Color := clWindowText;
            end;
            RzStringGrid1.Canvas.FillRect( Rect );
            RzStringGrid1.Canvas.TextRect( Rect, Rect.Left + 2, Rect.Top + 2,
                                           RzStringGrid1.Cells[ ACol, ARow ] );
          end;
        • #1260
          Barry Wood
          Participant

            Oops, sorry, yes I got that wrong!

            But thanks for the code example, works a treat …

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.