combobox的问题:在输入文本时,如何查询输入的文本是否已经存在于items,如果是,程序继续执行,如果不是,提示重新输入

解决方案 »

  1.   

    把combobox的style属性设为DropDownList
      

  2.   

    var flag:Boolean;flag:=true;
    for i:=0 to combobox1.items.count-1 do
      if str=combobox1.items[i] then
        begin
          //继续执行
         flag:=false;
         break;
        end;
    if flag then
      //重新输入
      

  3.   

    combobox自己有没有这样的属性
      

  4.   

    没有这样的属性在combobox的onexit事件里写代码检测吧,不麻烦的如果重复
    combobox.segfocused;
    showmessage('....');
      

  5.   

    Combobox1.AutoComplete:=false;
    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    Var
      I:integer;
    begin
      if key=#13 then
      begin
        for I:=0 to Combobox1.Items.Count-1 do
          if Combobox1.Items[I]=Combobox1.Text then
            showmessage('存在');
      endend;
      

  6.   

    把combobox的style属性设为csDropDownList,
    这样的话你就不用输入文本了。更何来判断?
      

  7.   

    if cb1.items.Count = 0 then
        begin
         {加语句}   
        end
      else
        {加语句}
      

  8.   

    楼主的要求本来就是不要人自己输入,只要combobox中存在的,设成csDropDownList后,还是可以在里面输入的,它会自动定位到想要的item上去的
      

  9.   

    既然delphi有这个功能,何必再多此一举去自己写程序来判断呢?
      

  10.   

    TStrings有一个方法,Indexof,返回值不等于-1就表示有了。