1. 程式人生 > >COMBOBOX多選

COMBOBOX多選

 procedure TForm1.ComboBox1DropDown(Sender: TObject);
begin
  PrevIndex := ComboBox1.ItemIndex;
  cText := ComboBox1.Text;
end;

procedure TForm1.ComboBox1Select(Sender: TObject);
begin
  if (ComboBox1.ItemIndex <> PrevIndex) and (ComboBox1.ItemIndex > -1) then
  begin
    if Trim(cText) = '' then
      cText := ComboBox1.Items[ComboBox1.ItemIndex]
    else
      cText := cText + ',' + ComboBox1.Items[ComboBox1.ItemIndex];
    Timer1.Enabled := False;
    Timer1.Enabled := True;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Interval := 50;
  Timer1.Enabled := False;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Trim(cText) <> '' then
  begin
    Timer1.Enabled := False;
    ComboBox1.Text := cText;
    ComboBox1.SelectAll;
    cText := '';
  end;
end;