有一个Listbox和combobox,我想通过双击listbox将选中的值加入到combobox中去,如果重复的话就不加入,请问怎么做?

解决方案 »

  1.   

    在Listbox的OnDblClick事件里写
    var
      i: integer;
    begin
      for i := 0 to ComboBox1.Items.Count - 1 do begin
        if ComboBox1.Items.Strings[i] = Listbox1.Items.Strings[Listbox1.ItemIndex] then 
          exit;
      end;
      ComboBox1.Items.Add(Listbox1.Items.Strings[Listbox1.ItemIndex]);
    end;
      

  2.   

    procedure TForm1.ListBox1DblClick(Sender: TObject);
    begin
    if ComboBox1.Items.IndexOf(ListBox1.Items[ListBox1.ItemIndex])=-1 then
      ComboBox1.Items.Add(ListBox1.Items[ListBox1.ItemIndex]);
    end;