表格控件表头栏目(Column)与数据表头步
不用手工增加栏目的列,也就是Column,由数据库的查询结果自动创建。
用的是Delphi2010,安装了Dev,用CxGrid显示数据库查询结果。用什么控件没有关键,道理相同的。
procedure TForm1.SpeedButton1Click(Sender: TObject); Var LCount,I:integer; begin ADOQuery1.Close; for I := 0 to Self.cxGrid1DBTableView1.ColumnCount- 1 do begin Self.cxGrid1DBTableView1.Columns[i].Destroy; end; With ADOQuery1 do begin Close; SQL.Clear; SQL.Add(Memo1.Text); Open; end; Line:=ADOQuery1.FieldList.Count; for i := 0 to (Line -1) do begin Self.cxGrid1DBTableView1.CreateColumn;
//Self.cxGrid1DBTableView1.Columns[i].Width:=50; 设置栏目的宽度 end; for I := 0 to Line - 1 do begin Self.cxGrid1DBTableView1.Columns[i].DataBinding.FieldName:=ADOQuery1.FieldList.Strings[i]; end; end;