有将近1000项选项,
需求,在Combobox输入字头,自动筛选出以该字头为头的所有选项。看了很多文章说的都不是很符合要求小弟是新人,分不多。

解决方案 »

  1.   

    combobox的items是一个Tstrings类型,它有一个方法是indexof ,是一个虚态方法,实现过程如下:
    function IndexOf(const S: string): Integer;
    begin
      for Result := 0 to GetCount - 1 do
        if CompareStrings(Get(Result), S) = 0 then Exit;
      Result := -1;
    end;
    你可以对此进行修改, 如:Procedure deleteNotSelectindex(const S: string);
    var
      Count:integer
    begin
      with ComboBox1 do
      begin
        for Count:= 0 to ComboBox1.items.GetCount - 1 do
          if CompareStrings(Copy(ComboBox1.items.Get(Result),1,1), Copy(S,1,1)) = 0 then
           ComboBox1.items.delete(Count);
      end;
    end;
    在进行这个操作之前,先把combobox的items做一个副本,以便回复!
      

  2.   

    还有一个如何判断Combobox.text是否为空
    用combobox.text=''
    好像不行
      

  3.   

    如果这些选项是从数据库来的话,那比较方便,不用备份items了。判断为空,为何不能用text呢? 如果是因为空格的原因的话,试试trim(combobox1.text) = ''