Search code examples
delphidevexpresstcxgrid

delphi cxgrid restrict characters


We are working in Delphi 2006 with devexpress.

We have a cxGrid. We want to restrict the entry of values for a number column, integers between 0 and 999. If I set the property type to a SpinEdit the initial value is always 0 which is unwanted.

So I left the property value on the column null and set the datatype on the databinding of the column to Smallint. That works for the most part but an 'e' and '.' and '+' and '-' can still be entered into the column which causes exceptions.

Is some simple way to exclude the 'e' and '.' and '+' and '-' from being entered into the column?


Solution

  • The initial 0 Value can be prevented by setting UseNullString to true.

    The input of unwanted characters can handled by

    procedure TForm1.ViewEditKeyPress(Sender: TcxCustomGridTableView; AItem: TcxCustomGridTableItem;
      AEdit: TcxCustomEdit; var Key: Char);
    begin
       if AItem = TheColumnWithSpinEdit then
         if (not (Key in ['0'..'9',#8])) then Key := #0;
    end;