2010-06-17 54 views
0

我有組合框具有值category1和category2 ... category1有鉛筆,食物,雜誌,報紙等項目... 當我選擇category1時,我想要檢索項目tdbmemo.then在tdbmemo相同的項目,我想在 checklistbox顯示...我不知道該怎麼辦......我使用clcat.items.add顯示項目,但項目沒有顯示在組合框中顯示tdbmemo中的項目

procedure TfrmSysConfig.FillInCheckListClCat; 
var 
    sTable : string; 
    sqlCat : TIBOQuery; 
    iIndex :integer; 
    lstCat : TStringList; 
begin 
    if tblMain.FieldByName('POS_ReceiptCatBreakDown').AsString <> '' then begin 
    sqlCat := TIBOQuery.Create(nil); 
    sqlCat.IB_Connection := dmMain.db; 
    lstCat := TStringList.Create; 
    try 
     sqlCat.SQL.Text := 'SELECT code FROM ' + cboCategory.Value; 
     sqlCat.Open; 
     while not sqlCat.Eof do begin 
     clCat.Items.Add(sqlCat.FieldByName('Code').AsString); 
     sqlCat.Next; 
     end; 
    finally 
     lstCat.Free; 
     sqlCat.Free; 
    end; 
    end; 
end; 

回答

0

sqlCat.SQL.Text:='SELECT code FROM'+ cboCategory.Value; - 我相信這是行不通的... select子句就像「select * from table where condition」。

我以前用IBObjects工作過,並且在這些組件上有一些有用的屬性。

使用IB_ComboBox作爲列表(category1和category2等)並將其鏈接到一個IB_Memo(我不知道100%這是什麼名字,但你會發現)並且使用IBTable你可以設置一個IB_Memo過濾它。他們在網站上也有非常有用的文檔。

最好的問候,

+0

斑點!直接閱讀缺失的「From Table where x =」部分。 – 2010-06-17 08:14:18

0

繼承人我是如何做到的? 首次下降的形式組合框,數據庫備註和檢查列表框(因爲你已經有)三個部分組成。

然後在單位「」變種「添加一個字符串列表變量部分我正在命名它在FORMCREATE事件的可疑交易報告

strs : tstringlist; 

下一個 初始化的TStringList的項目,清除組合框,並添加‘類別1’和」類別2' 項目.....繼承人如何做到這一點

procedure TForm2.FormCreate(Sender: TObject); 
begin 
    strs := TStringList.create; 
    strs.Add('food'); 
    strs.Add('magazine'); 
    strs.Add('pencil'); 
    strs.Add('newspaper'); 
    Combobox1.Items.clear; 
    ComboBox1.Items.add('category1'); 
    ComboBox1.Items.add('category2'); 

end; 
未來

我們編寫事件處理程序組合框的變化和更新checklistbox和數據庫備註寫代碼:

procedure TForm2.ComboBox1Change(Sender: TObject); 
begin 
    if ComboBox1.ItemIndex = 0 then 
    DBMemo1.lines.AddStrings(strs); 
    CheckListBox1.Items.addstrings(strs); 
end; 

繼承人的完整代碼:

unit project1; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls, DBCtrls, CheckLst; 

type 
    TForm2 = class(TForm) 
    ComboBox1: TComboBox; 
    DBMemo1: TDBMemo; 
    CheckListBox1: TCheckListBox; 
    procedure FormCreate(Sender: TObject); 
    procedure ComboBox1Change(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form2: TForm2; 
    strs : tstringlist; 

implementation 

{$R *.dfm} 

procedure TForm2.ComboBox1Change(Sender: TObject); 
begin 
    if ComboBox1.ItemIndex = 0 then 
    DBMemo1.lines.AddStrings(strs); 
    CheckListBox1.Items.addstrings(strs); 
end; 

procedure TForm2.FormCreate(Sender: TObject); 
begin 
    strs := TStringList.create; 
    strs.Add('food'); 
    strs.add('magazine'); 
    strs.Add('pencil'); 
    strs.add('newspaper'); 
    combobox1.Items.clear; 
    ComboBox1.items.add('category1'); 
    ComboBox1.items.add('category2'); 

end; 


end. 

我希望這會幫助,請詢問是否有任何不明白你或你不理解的東西,生病嘗試以更詳細解釋。

相關問題