如何限制combobox中的内容只可以是数字,有属性可以直接设置吗?还是要写代码?

解决方案 »

  1.   

    在Combobox的KeyPress事件中判断:
    if not key in ['0..9',#45] then key=#0
    具体也不太记得了,反正是这么控制的
      

  2.   

    if not key in ['0'..'9',#8,#13] then Key :=#0
      

  3.   

    我在keypress事件里写了此代码,可以控制,但是不能控制输入汉字
    If KeyAscii < 48 Or KeyAscii > 57 Then
       KeyAscii = 0
       MsgBox "输入数字。", vbInformation, "提示"
    End If
      

  4.   

    上面回答的也差不多了吧,还要防止用Ctrl+V向里粘。
      

  5.   


    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9'] )then
        begin
          showmessage('·&Ccedil;·¨×&Ouml;·&ucirc;');
          key:=#0;
        end;
    end;