在KEYPRESS事件中
if not (Key in ['0'..'9']) then Key := #0 ;

解决方案 »

  1.   

    1.dbgrid中这一列绑定的字段假设为table1 中的 a1:
      var b:string ; 
      with table1 do
       begin
        close;
        open;
        b:= fieldbyname('a1').asstring;
        if not(b in ['0'..'9']) then
           b:=0;
       end;
      

  2.   

    //在KEYPRESS事件中可用
    procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
    if not (Key in ['0'..'9']) then Key := #0 ;
    end;
      

  3.   

    procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
       if (Sender as TDBGrid).SelectedField.FieldName ='Field1' then
        if not (Key in ['0'..'9']) then Key := #0 ;
    end;//其中Field1就是你要限制的字段名