2

StringGridがあり、セルのみ1またはを入れたい0。StringGridGetEditMaskを使用しようとしています

procedure TForm1.StringGrid1GetEditMask(Sender: TObject; ACol,
  ARow: Integer; var Value: String);
begin
  Value := '0';
  if not (strToInt(Value) in [0,1]) then value := #0;
end;

しかし、0から9までのすべての数値を入力できます。0と1を除くすべての数値をフィルタリングするにはどうすればよいですか?

4

2 に答える 2

3

あなたの意図のために、あなたはTStringGridクラスをサブクラス化する必要があり、そのようなサブクラスでは、このインターポーザークラスに示されているようなインプレースエディターの例えばOnKeyPressイベントに割り当てます:

type
  TStringGrid = class(Grids.TStringGrid)
  private
    procedure InplaceEditKeyPress(Sender: TObject; var Key: Char);
  protected
    function CreateEditor: TInplaceEdit; override;
  end;

implementation

{ TStringGrid }

function TStringGrid.CreateEditor: TInplaceEdit;
begin
  Result := inherited CreateEditor;
  TMaskEdit(Result).OnKeyPress := InplaceEditKeyPress;
end;

procedure TStringGrid.InplaceEditKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in [#8, '0', '1']) then
    Key := #0;
end;
于 2013-03-26T19:48:36.610 に答える
2

あなたはその出来事を誤解しOnGetEditMaskました。変更が許可されている新しい文字列ではなく、コントロールにマスクValueを与える必要がある場所です。ただし、残念ながら、マスクを編集すると、要求した機能が許可されません。

于 2013-03-26T19:34:44.740 に答える