1、在一个form窗体中,有3个combobox控件,combobox1要显示stu表中的xh字段,combobox2要显示ust表中的xm字段,combobox3要显示ust中的sup字段。如果只有一个combobox控件,我可以在FormShow中实现。2、在edit控件中,它的text中要只允许输入数字,并且要求保留小数2位,如何实现?不胜感激!!!

解决方案 »

  1.   

    三个和一个有什么不同啊?都写在FormCreate里不行吗?OnKeyDown
    begin
      if ((key < '0') or (key > '9')) and (key <> '.') and (key <> 退格键) then
        key:= #0;
      if (key='.') and (Pos('.', Edit.text) > 0) then
        key:= #0;
      if (Pos('.', Edit.text) > 0) and ((length(edit.text)-(pos('.', Edit.text))>=2) then
        key:= #0;
    end;以上为伪代码。未测试。
      

  2.   

    如果你知道在FORMSHOW中显示出一个COMBOBOX内容,那么第二个,第三个可以采用同样的方法。第二个问题,你可以采用MaskEdit(DELPHI自带的控件). 只要设置输入的格式就行了。或者编程程实现如楼上所说。^-^
      

  3.   

    combobox1.clear;
    with AdoQuery1 do
    begin
      close;
      sql.clear;
      sql.add('select distinct xh from stu');
      Open;
      while not eof do
        comboBox1.Items.add(FieldByName('xh').asString);
    end;依此类推。
      

  4.   

    第一个你自己都知道方法就不说了
    第二个下面的代码你看看啦  希望对你有帮助用一个TMaskEdit限制一下格式   再在OnKeyDown事件下写一个
    if  not (key in ['0'..'9',#8,'.']) then 
    begin
      key:=0;
    end;
      

  5.   

    combobox1.clear;
    with AdoQuery1 do
    begin
      close;
      sql.clear;
      sql.add('select distinct xh from stu');
      Open;
      while not eof do 
       bgein
        comboBox1.Items.add(FieldByName('xh').asString);
        next; //应该加个Next,不然只会显示一个记录...
       end;
    end;