在combobox中有4个选项a,b,c,d。用鼠标选择时可以利用onpress或onclick触发事件,运行里面的代码。可是当combobox中的选项被程序自动选择时,怎么自动运行里面的程序啊?

解决方案 »

  1.   

    onchange事件也是鼠标触动的。
      

  2.   

    我也遇到这个问题,我看delphi7的bug来的,我继承tcombobox解决了问题
    unit MYCOMBO;interfaceuses  Messages, Classes, StdCtrls;type
      TMyComboBox = class(TComboBox)
      private
        FOnItemChanged : TNotifyEvent;
      protected
        procedure WndProc(var Message: TMessage); override;
        procedure Change; override;
      published
        property OnItemChanged: TNotifyEvent read FOnItemChanged write FOnItemChanged;
      end;procedure Register;implementation{______________________________________________________________________________}
    procedure Register;
    begin
      RegisterComponents('MikoComponent',[TMyComboBox]);
    end;{______________________________________________________________________________}
    procedure TMyComboBox.WndProc(var Message: TMessage);
    begin
      inherited WndProc(Message);
      if (Message.Msg = CB_SETCURSEL) then
        if Assigned(FOnItemChanged) then
           FOnItemChanged(Self);
    end;procedure TMyComboBox.Change;
    begin
      if Assigned(FOnItemChanged) then
        FOnItemChanged(Self);
      inherited Change;
    end;
    end.将以前的onchange事件换成OnItemChanged就可以了