简体   繁体   中英

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM