ComboBox 如何給定初始值的問題 |
|
yu168
一般會員 發表:29 回覆:27 積分:16 註冊:2002-06-28 發送簡訊給我 |
請教各位:
有沒有什麼比較好的方法可以在 FormCreate 的時候預設 ComboBox 的選項, 並且可已觸發 OnChange 事件?? 因為我發現 TComboBox 的 OnChange 沒辦法用程式去觸發它.....我查 Help得到的答案竟是沒辦法, 底下是Help 的說明 ---------------------------------------------------------------------------------------------------------------- Note: OnChange only occurs in response to user actions. Changing the Text property programmatically does not trigger an OnChange event. ---------------------------------------------------------------------------------------------------------------- 底下是我的測試程式, 我需要在程式一執行的時候, Label2.Caption 就會設成 ComboBox1.Text; <textarea class="delphi" rows="10" cols="60" name="code"> interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm23 = class(TForm) ComboBox1: TComboBox; Label1: TLabel; Label2: TLabel; procedure ComboBox1Change(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form23: TForm23; implementation {$R *.dfm} procedure TForm23.ComboBox1Change(Sender: TObject); begin Label2.Caption := ComboBox1.Text; end; procedure TForm23.FormCreate(Sender: TObject); begin ComboBox1.Items.Add('First Choice'); ComboBox1.Items.Add('Second Choice'); ComboBox1.Items.Add('... Choice'); ComboBox1.Items.Add('... Choice'); ComboBox1.ItemIndex := 1; end; end. </textarea> |
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
<textarea class="vb" rows="10" cols="60" name="code">
procedure TForm23.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Add('First Choice');
ComboBox1.Items.Add('Second Choice');
ComboBox1.Items.Add('... Choice');
ComboBox1.Items.Add('... Choice');
ComboBox1.ItemIndex := 1;
ComboBox1.OnChange(ComboBox1);
end;
</textarea> Fishman
------
Fishman |
yu168
一般會員 發表:29 回覆:27 積分:16 註冊:2002-06-28 發送簡訊給我 |
原來如此!! 感謝!!
===================引 用 文 章=================== <textarea class="vb" rows="10" cols="60" name="code">procedure TForm23.FormCreate(Sender: TObject); begin ComboBox1.Items.Add('First Choice'); ComboBox1.Items.Add('Second Choice'); ComboBox1.Items.Add('... Choice'); ComboBox1.Items.Add('... Choice'); ComboBox1.ItemIndex := 1; ComboBox1.OnChange(ComboBox1); end; </textarea> Fishman |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |