Recent

Author Topic: [SOLVED] TStringGrid: Best way to set default editor's colors?  (Read 2225 times)

Gary Randall

  • Jr. Member
  • **
  • Posts: 70
[SOLVED] TStringGrid: Best way to set default editor's colors?
« on: December 21, 2014, 05:39:23 pm »
My stringgrid uses the default editor (cbsAuto) for several columns which is selected automatically when cells are selected.  I'd like to be able to set the editor's background and text colors.  What's the best way?

Gary
« Last Edit: December 22, 2014, 11:05:04 pm by Gary Randall »
Windows 7 Home Premium 64 bit - SP 1
Lazarus Version #: 1.8.0; FPC Version: 3.0.4
SVN Revision 56594
i386-win32-win32/win64

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: TStringGrid: Best way to set default editor's colors?
« Reply #1 on: December 21, 2014, 06:01:51 pm »
I suggest using OnSelectEditor event:
Code: [Select]
procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
  var Editor: TWinControl);
begin
  if (Editor is TStringCellEditor) then
  begin
    TStringCellEditor(Editor).Font.Color:=clRed;
    TStringCellEditor(Editor).Color:=clYellow;
  end
  else if (Editor is TPickListCellEditor) then
  begin
    TPickListCellEditor(Editor).Font.Color:=clBlue;
    TPickListCellEditor(Editor).Color:=clYellow;
  end;
end;

Gary Randall

  • Jr. Member
  • **
  • Posts: 70
Re: TStringGrid: Best way to set default editor's colors?
« Reply #2 on: December 22, 2014, 11:03:51 pm »
Thank you for the code engkin.   It worked perfectly.  And thank you for introducing me to TStringCellEditor.  I can't believe I overlooked it.  Now I'm able to tweak the editor the way I want.

Gary

Windows 7 Home Premium 64 bit - SP 1
Lazarus Version #: 1.8.0; FPC Version: 3.0.4
SVN Revision 56594
i386-win32-win32/win64

 

TinyPortal © 2005-2018