如TListBox中有
张三
李四
王二
如选择了张三再选择李四,那么框中变为:张三、李四,而不是李四
再在下拉列表中选择王二,那么框中变为:张三、李四、王二,而不是王二

解决方案 »

  1.   

    不清楚楼主的意思是什么,是在ListBox中选名字,还是把名字写进ListBox?
      

  2.   

    你把ListBox设为可以多选,
    不知道是不是这个意思.
      

  3.   

    对不起,一时写错了。是要在 ComboBox上实现上述的效果。
    :)
      

  4.   

    请参看这个帖子(本帖分照发,各位留个名)
    http://topic.csdn.net/u/20080510/15/4dd5fadc-563a-42e4-af64-d3831ef89725.html
      

  5.   

    再来一次, 这次用消息,不用TTimer了啊,呵呵
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls;const
      WM_SHOWCOMBTEXT = WM_USER + 12345; //定义一个消息显示ComboBox.Texttype
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        procedure ComboBox1DropDown(Sender: TObject);
        procedure ComboBox1Select(Sender: TObject);
      private
        { Private declarations }
        cText: string;
        PrevIndex: Integer;
        procedure DoShowCombText(var Msg: TMessage); message WM_SHOWCOMBTEXT;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}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];
        PostMessage(Handle, WM_SHOWCOMBTEXT, 0, 0);
      end;
    end;procedure TForm1.DoShowCombText(var Msg: TMessage);
    begin
      if Trim(cText) <> '' then
      begin
        ComboBox1.Text := cText;
        ComboBox1.SelectAll;
        cText := '';
      end;
    end;end.