i have combobox that have value category1 and category2...the category1 have items like pencil,food,magazine,newspaper... when i choose category1, i want to retrieve the items in tdbmemo.then the same items in tdbmemo i want to display in checklistbox...i dont know how to do...i use clcat.items.add to display the item but the items is not display
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;
sqlCat.SQL.Text := 'SELECT code FROM ' + cboCategory.Value; - i believe this wouldn't work...a select clause is something like "select * from table where condition".
i've worked a while ago with IBObjects, and there are some useful properties on those components.
use IB_ComboBox for the list(category1 and category2,etc) and link it to a IB_Memo (i'm not sure 100% this is the name, but you'll figure out) and with a IBTable you can set an filter over it. also they have on the site a very useful documentation.
best regards,
heres how i did it... first drop three components on form combobox,dbmemo and check listbox(as you already have).
then add a string list variable in the units ''var' section i am naming it strs
strs : tstringlist;
next in the formcreate event initialize tstringlist items,clear combo box and add 'category1' and 'category2' items..... heres how to do it
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;
next we write event handler for combobox change and write code for updating checklistbox and dbmemo :
procedure TForm2.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.ItemIndex = 0 then
DBMemo1.lines.AddStrings(strs);
CheckListBox1.Items.addstrings(strs);
end;
heres the complete code:
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.
i hope this help ,please ask if something is unclear to you or you dont understand something, ill try to explain in more details.
精彩评论