我想要在combobox 下拉列表中选中某一项后,按删除按钮,则那1项就没了,下面的项自动往上排。怎样实现啊。
ComboBox2.Items.Add可以用,那是不是有个对应的ComboBox1.Items。delete,怎样用啊?急!

解决方案 »

  1.   

    ComboBox1.Items.Delete(ComboBox1.ItemIndex);
      

  2.   

    ComboBox1.Items.Delete(ComboBox1.ItemIndex);
       ComboBox1.Refresh;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      I : integer;
    begin
      I:=Combobox1.ItemIndex;
      if i>=0 then
      begin
        Combobox1.Items.Delete(i);
        if I=0 then
          if I-1<Combobox1.Items.Count then Combobox1.ItemIndex:=0;
        if (i>0) and (I-1<Combobox1.Items.Count) then
         Combobox1.ItemIndex:=i-1  end
       else
          Combobox1.ItemIndex:=-1;end;
      

  4.   

    ComboBox1.Items.Delete(ComboBox1.ItemIndex)
    ComboBox1.Refresh
      

  5.   

    cdsgajxlp(起名很难): if I-1<Combobox1.Items.Count then Combobox1.ItemIndex:=0;
    应该为 if I+1<Combobox1.Items.Count then Combobox1.ItemIndex:=0;吧。因Combobox1.ItemIndex应该是从0开始计的吧。(0、1、2……)。还要算上删除的是最后1个,其它Combobox1.ItemIndex值不用变。Combobox1.ItemIndex是指当前项吗?如果是当前项,那Combobox1.ItemIndex:=i-1可以删除完某项后将下面的项往上移吗?还有Combobox1.ItemIndex:=-1;是什么意思啊
      

  6.   

    来晚了啊
    combobox1.Items.Delete(combobox1.ItemIndex);
      

  7.   

    谁能解释一下cdsgajxlp(起名很难)的,我觉得有些不对啊
      

  8.   

    ComboBox1.Refresh;
    有时会出错的
      

  9.   

    上面说的很详细,结贴吧
    另开一贴,给你详细解释那一段ComboBox1.ItemIndex := -1 表示一项也不选,即无选择项
      

  10.   

    zhouzhouzhou"ComboBox1.Refresh;有时会出错的" 会出什么错?
    hangguojun就在这里解释啊。我可以再加分,不需要另开一贴