Procedure TForm1.Combobox1Select(Sender:TObject);
begin
  Combobox1.Text:='000';
  showmessage('ok');
end;建立Form1,加入Combobox1,给Combobox1加入选项
123
456
789而上面的事件过程中的代码,实现combobox选择后,combobox强行赋值为000,但执行一下就会发现,如果是用键盘按1从而选择123,combobox是变成000了,出现ok提示框后,也还是000;
但如果是用鼠标直接选择123,combobox是变成000,但出现ok提示框后,combobox又变回123了。
用上下方向键选择123,也是同样情况。高手指点,如何解决这个问题?是不是控件的BUG???

解决方案 »

  1.   

    这明显是你自己设计的问题, 并非什么Bug
    在Combobox选择过程中你非得强行给他赋值'000', 当然在选择操作时只能显示'000'了
      

  2.   

    ourlin(寒江独钓) 拜托请先看清问题:
    ------------------
    第1种情况:输入1,
    combobox显示000
    showmessage显示ok
    最后combobox显示000------------------
    第2种情况:用上下键选择123
    combobox显示000
    showmessage显示ok
    最后combobox显示000------------------
    第3种情况:用鼠标选择123
    combobox显示000
    showmessage显示ok
    最后combobox显示123其实我真正想实现的目的是选择过程中增加数据处理过程,为了问题清楚才写出上面的问题。
    真正的程序是:
    Procedure TForm1.Combobox1Select(Sender:TObject);
    begin
      Combobox1.Text:=copy(Combobox1.Text,1,1);
    end;建立Form1,加入Combobox1,给Combobox1加入选项
    1-正常
    2-禁止
    3-注销Combobox1选项中,数字为实际使用的,汉字部分只是说明,但不能参与具体运算,所以要在选择后处理一下,只留前面实际使用的数字部分。哪位有更好的解决方法???
      

  3.   

    一般都是 做  combox。text的属性做处理。
    很少在选的过程中对鼠标经过的数据做处理啊。
      

  4.   

    哎,怪我问题说的不清楚,我再简单点说。combobox点选择下箭头时,出现下拉框,显示里面数据为
    1-正常
    2-禁止
    3-注销例如要选择‘2-禁止’项,鼠标点选后,combobox框中应该显示‘2-禁止’。
    但我需要在鼠标点选后,让combobox框中显示‘2’。这下说清楚了吧!
      

  5.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, SUIComboBox;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        procedure FormCreate(Sender: TObject);
        procedure ComboBox1Select(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      ComboBox1.Items.Clear;
      ComboBox1.Items.Add('1-正常');
      ComboBox1.Items.Add('2-禁止');
      ComboBox1.Items.Add('3-注销');
    end;procedure TForm1.ComboBox1Select(Sender: TObject);
    begin
      ComboBox1.Text:=Copy(ComboBox1.Text,1,1);
      showmessage('ok');
    end;end.
    干脆把完整代码贴出来。我的目的就是:
    在选择‘1-正常’后,在Combobox框里显示‘1’。
    在选择‘2-禁止’后,在Combobox框里显示‘2’。
    在选择‘3-注销’后,在Combobox框里显示‘3’。
    如何实现?
    试试在Combobox框里输入1、2、或3的数字选择,和鼠标点选,有何不同!
    正常情况下,在Combobox框里输入数字2,在Combobox框里会显示‘2-禁止’,
    但因为有如下处理代码:
    Procedure TForm1.Combobox1Select(Sender:TObject);
    begin
      Combobox1.Text:=copy(Combobox1.Text,1,1);
    end;
    所以选择后,在Combobox框里会显示‘2’,去掉了‘-禁止’。但用鼠标选择,开始Combobox框里会显示‘2’,然后showmessage显示‘ok’后,Combobox框里最后还是显示‘2-禁止’。
    另外更正,鼠标点选和上下键选择结果相同,我上面说错了!
      

  6.   

    不是控件有bug,而是你的用法不对。瞧我的
    procedure TForm1.ComboBox1Select(Sender: TObject);
    var
      index:integer;
    begin
      index := ComboBox1.ItemIndex;
      ComboBox1.Items.Clear;
      ComboBox1.Items.Add('1');
      ComboBox1.Items.Add('2');
      ComboBox1.Items.Add('3');
      ComboBox1.ItemIndex := index;
    end;procedure TForm1.ComboBox1DropDown(Sender: TObject);
    begin
      ComboBox1.Items.Clear;
      ComboBox1.Items.Add('1-正常');
      ComboBox1.Items.Add('2-禁止');
      ComboBox1.Items.Add('3-注销');
    end;
      

  7.   

    merkey2002(小样的):你的方法试过了,有一个问题,
    比如combobox框里显示‘2’时,按出下拉选择框,此时combobox框里变成显示‘2-禁止’,
    如果不用鼠标选择一个下拉框中的选项,而用鼠标点击其他地方的话,下拉框消失后,combobox框里还是显示‘2-禁止’。所以,根据你的代码更改如下,就是增加了一个CLOSEUP事件代码:procedure TForm1.ComboBox1Select(Sender: TObject);
    var
      index:integer;
    begin
      index := ComboBox1.ItemIndex;
      ComboBox1.Items.Clear;
      ComboBox1.Items.Add('1');
      ComboBox1.Items.Add('2');
      ComboBox1.Items.Add('3');
      ComboBox1.ItemIndex := index;
    end;procedure TForm1.ComboBox1DropDown(Sender: TObject);
    begin
      ComboBox1.Items.Clear;
      ComboBox1.Items.Add('1-正常');
      ComboBox1.Items.Add('2-禁止');
      ComboBox1.Items.Add('3-注销');
    end;procedure TForm1.ComboBox1CloseUp(Sender: TObject);
    var
      index:integer;
    begin
      index := ComboBox1.ItemIndex;
      ComboBox1.Items.Clear;
      ComboBox1.Items.Add('1');
      ComboBox1.Items.Add('2');
      ComboBox1.Items.Add('3');
      ComboBox1.ItemIndex := index;
    end;
      

  8.   

    虽然上面的代码已经实现我要的功能,但我想说的问题是:ComboBox控件中,用鼠标点选和输入选项内容选择,虽然都触发onselect事件,但结果并不相同。例如下面的代码:
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      ComboBox1.Items.Clear;
      ComboBox1.Items.Add('1-正常');
      ComboBox1.Items.Add('2-禁止');
      ComboBox1.Items.Add('3-注销');
    end;procedure TForm1.ComboBox1Select(Sender: TObject);
    begin
      ComboBox1.Text:=Copy(ComboBox1.Text,1,1);
      showmessage('ok');
    end;用鼠标点选选项2,结果是‘2-禁止’
    输入数字2自动选择选项2,结果是‘2’