StringGrid: how to set MaxLength for a specific Column

Giganews Newsgroups
Subject:StringGrid: how to set MaxLength for a specific Column
Posted by: Gerhard Zampich (ma…@Zampich.de)
Date:Fri, 04 Jul 2008

Hello,

I am trying to limit the data entry in a column of a stringgrid to a
specific MaxLength.
I have done the following:

type
  TStringGridCracker = class(TStringGrid)
  end;

procedure TMainForm.GridSetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
begin
  if ( ACol = 5 )
  then with
TStringGridCracker(Sender)

  do if (InplaceEditor <> nil
)
  then TEdit(InplaceEditor).MaxLength := 55;
end;

This works good, with one exception:
When the cell at column 5 holds already 55 chars when the cell is
selected, one can enter a 56th character.
So it seems that the SetEditText event is to late to set maxlength.
What is the correct way to set TEdit(InplaceEditor).MaxLength?

Regards
Gerhard

Replies