全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:853
推到 Plurk!
推到 Facebook!

有關查詢欄位清除問題

答題得分者是:chih
Fen
一般會員


發表:18
回覆:17
積分:7
註冊:2003-10-20

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-11-18 15:23:48 IP:61.219.xxx.xxx 未訂閱
各位大大: 我用ADOTable從資料庫抓取資料,抓出的資料從多個ConboBox顯示出來,設一個查詢鈕,使資料可以顯示在DBGrid上,另外我設了一個取消鈕,按下它之後我希望能將所有ComboBox清空,請問應該如何做ㄋ?
chih
版主


發表:48
回覆:1186
積分:639
註冊:2002-04-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-11-18 15:47:05 IP:218.164.xxx.xxx 未訂閱
procedure TForm1.Button1Click(Sender: TObject);
var
  j:integer;
begin
 for j := 1 to Form1.ComponentCount - 1 do
    begin
      if (Components[j] is TComboBox) then
        begin
         (Components[j] as TComboBox).Items.Clear;
         (Components[j] as TComboBox).Text:='';
        end;
    end;
end;
TRY TRY SEE
發表人 - chih 於 2003/11/18 15:48:46
Fen
一般會員


發表:18
回覆:17
積分:7
註冊:2003-10-20

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-11-18 16:49:17 IP:61.219.xxx.xxx 未訂閱
謝謝你,用你的方法在小小修改一下,此問題已經解決; 修改的原因是因為你的方法將欄位清空後,下一次要在查詢時,ComboBox的資料就沒有了,所以我在程式後面再加回原來的資料,如下:    procedure TMainForm.btnclearClick(Sender: TObject); begin       if (ComboBoxSeasonYear is TComboBox) then            begin                (ComboBoxSeasonYear as TComboBox).Items.Clear;                (ComboBoxSeasonYear as TComboBox).Text:='';                    TableInquire.TableName := 'VW_SeasonYear';                 TableInquire.Active := True;                 while not TableInquire.eof do                 begin                      ComboBoxSeasonYear.Items.Add                       (TableInquire.FieldValues['SeasonYear']);                      TableInquire.Next;                 end;                 TableInquire.Active := False;            end;    不過程式跑起來,在按下清除時會變一個一個的消失,不知道我這樣寫是不是由何瑕疵?
chih
版主


發表:48
回覆:1186
積分:639
註冊:2002-04-02

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-11-20 09:13:59 IP:218.164.xxx.xxx 未訂閱
1.同時更新ComboBox的內容
procedure TMainForm.btnclearClick(Sender: TObject);
var
  j: integer;
begin
  for j := 1 to Form1.ComponentCount - 1 do
    begin
      if (Components[j] is TComboBox) then
        begin
          (Components[j] as TComboBox).Items.Clear;
          (Components[j] as TComboBox).Text := '';
        end;
      TableInquire.TableName := 'VW_SeasonYear';
      TableInquire.Active := True;
      while not TableInquire.eof do
        begin
          (Components[j] as TComboBox).Items.Add
            (TableInquire.FieldValues['SeasonYear']);
          TableInquire.Next;
        end;
      TableInquire.Active := False;
    end;
end;
2.只有清除User 選擇條件,不更新ComboBox的內容
procedure TMainForm.btnclearClick(Sender: TObject);
var
  j: integer;
begin
  for j := 1 to Form1.ComponentCount - 1 do
    begin
      if (Components[j] is TComboBox) then
          (Components[j] as TComboBox).Text := '';
    end;
end;
TRY TRY SEE...^^
發表人 - chih 於 2003/11/20 15:08:06
系統時間:2024-09-09 1:55:31
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!