【求助】字段动态加到checkboxlist里,求代码。。在线等!!!(40)

  • 主题发起人 主题发起人 gu_leilei
  • 开始时间 开始时间
G

gu_leilei

Unregistered / Unconfirmed
GUEST, unregistred user!
现有张access表,字段分别是风,雨,雪,冰雹,雾。用checkboxlist的items属性只能是静态的添加,现在想动态的把字段添加到checkboxlist里面,求代码。。急!!!
 
囧,打错了。。是checklistbox
 
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, CheckLst, DB, ADODB;type TForm1 = class(TForm) CheckListBox1: TCheckListBox; Button1: TButton; Memo1: TMemo; ADOQuery1: TADOQuery; procedure Button1Click(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var i:integer; st:tstringlist;begin st:=tstringlist.Create; while not adoquery1.Eof do begin st.Add(adoquery1.fieldbyname('天气').AsString); adoquery1.Next; end; for i:=0 to st.Count-1 do begin checklistbox1.Items.Add(st.Strings); end; st.Free;end;procedure TForm1.FormShow(Sender: TObject);begin with adoquery1 do adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('select 天气 from 表'); adoquery1.Open;end;end.
 
帮你顶,接个小分
 
你是要添字段还是记录啊?字段的话可以这样做:Var i:integer;with adoquery1 dobegin active := false; sql.clear; sql.add('select * from tablename'); active := true; checklistbox1.items.clear; for i:=0 to FieldCount-1 do begin checklistbox1.items.add(fields.FieldName); end;end;
 
顶,人气,现在新人少了!
 
谢谢大家~~~~~~
 
后退
顶部