在一个dbgrid中显示一个table中的内容,用户可以在dbgrid中修改值,但是在某一列中修改时只能让其输入数字而不能输入其他,这样的功能该如何实现呀??谢谢!

解决方案 »

  1.   

    通过字段的类型设置.
    如设为Float,int就输不入其它了.
      

  2.   

    可以不做处理
    这个可以由DataSet的字段属性来决定的, 如果该字段是数字, 用户不可能输入其他了~
      

  3.   

    假设这一列叫'Name',在DBGrid的OnKeyPress事件中:
    procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if DBGrid1.SelectedField.FieldName = 'Name' then
        if not (Key in ['0'..'9','.']) then
          Key := #0;
    end;
      

  4.   

    DBGrid的话,用TField.OnValidate也行.
      

  5.   

    sysu(死树)的方法可行,如果用TField.OnValidate来实现??
      

  6.   

    假设这一列叫'Name',在DBGrid的OnKeyPress事件中:
    procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
    begin
      if DBGrid1.SelectedField.FieldName = 'Name' then
        if not (Key in ['0'..'9','.']) then
          Key := #0;
    end;这个方法用的时候还是有一个问题,
    如果我把数字输入错误,然后我想用退格键消除最后一个数字,只要的话,
    我就无法用退格了。请问这个问题怎么解决了?