Home › Forums › Konopka Signature VCL Controls (formerly Raize Components) › TRzStringGrid Cell Colour
Tagged: VCL StringGrid
- This topic has 2 replies, 2 voices, and was last updated 2019-03-25 at 11:20 am by
Barry Wood.
-
AuthorPosts
-
-
March 24, 2019 at 8:57 am #1257
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?
-
March 24, 2019 at 12:16 pm #1258
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,
Rayprocedure 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; -
March 25, 2019 at 11:20 am #1260
Oops, sorry, yes I got that wrong!
But thanks for the code example, works a treat …
-
-
AuthorPosts
- You must be logged in to reply to this topic.