方法一:

var i: Integer;
Column: TcxGridDBColumn;
cxView: TcxGridDBTableView;
begin
cxView := Self.Levels[].GridView as TcxGridDBTableView;
if cxView.DataController.DataSource <> nil then
if cxView.DataController.DataSource.DataSet <> nil then
begin
cxView.ClearItems;
for i:= to cxView.DataController.DataSource.DataSet.FieldCount- do
begin
Column := cxView.CreateColumn;
Column.DataBinding.FieldName := cxView.DataController.DataSource.DataSet.Fields[i].FieldName;
Column.PropertiesClass := TcxTextEditProperties;
end;
end;
end;

方法一的补充

procedure CreateDynamicCols;
var
i, B_index: Integer;
begin
with BTVgather.Bands.Add do
begin
Caption := lcb1.Text;
Position.ColIndex := ;
end; for i := to dsgather.DataSet.FieldCount - do
begin
with BTVgather.Bands.Add do
begin
Position.BandIndex := ;
B_index := Index;
Caption := dsgather.DataSet.Fields[i].FieldName;
with BTVgather.CreateColumn do
begin
Position.BandIndex := B_index;
Caption := dsgather.DataSet.Fields[i].FieldName;
DataBinding.FieldName := dsgather.DataSet.Fields[i].FieldName;
PropertiesClassName := 'TcxCurrencyEditProperties';
TcxCurrencyEditProperties(Properties).DisplayFormat := ',0.00;-,0.00';
Width := 80;
//还可以绑定一个事件
OnGetDisplayText := Self.OnGetDisplayText;
end;
end;
end;
if BTVgather.Bands[].ChildBandCount = then
BTVgather.Bands[].Width :=
else
BTVgather.Bands[].Width := BTVgather.Bands[].ChildBandCount * ;
end;

方法二、

for i :=  to Query.FieldCount -  do
begin
cxGrid.CreateColumn;
cxGrid.columns[i].DataBinding.FieldName := Query.Fields[i].DisplayName;
cxGrid.Columns[i].Caption := 'XXXX';
cxGrid.Columns[i].Width :=;
end;

方法三、

procedure TFrmRuleEdit.CreateCols;
var
Column: TcxGridDBColumn;
begin
cdsPowerPrj.First;
while not cdsPowerPrj.Eof do
begin
Column := viewPower.CreateColumn;
Column.Caption := cdsPowerPrj.FieldByName('description').Text;
Column.DataBinding.FieldName := cdsPowerPrj.FieldByName('powerName').Text;
Column.PropertiesClassName := 'TcxCheckBoxProperties';
Column.Width := ;
cdsPowerPrj.Next;
end;
end;

Delphi控件cxGrid 如何动态创建列?的更多相关文章

  1. DevExpres表格控件运行时动态设置表格列

    本文是系列文章,陆续发表于电脑编程技巧与维护杂志. DevExpres产品是全球享有极高声誉的一流控件套包产品!国内典型用户包括:用友.金蝶.神州数码.工信部.中国石化.汉王科技等众多大中型科技型企业 ...

  2. cxgrid动态创建列

    cxgrid动态创建列 procedure TFrmRuleEdit.CreateCols;varColumn: TcxGridDBColumn;begincdsPowerPrj.First;whil ...

  3. delphi控件属性大全-详解-简介

    http://blog.csdn.net/u011096030/article/details/18716713 button 组件: CAPTION 属性 :用于在按钮上显示文本内容 Cancel ...

  4. DELPHI控件属性事件说明

    常用DELPHI控件属性事件设置说明 常用DELPHI控件属性设置说明目录TForm Class TPanel组件 TToolBar Class TToolButton Class TTimer Cl ...

  5. Delphi 控件大全

    delphi 控件大全(确实很全)   delphi 控件查询:http://www.torry.net/ http://www.jrsoftware.org Tb97 最有名的工具条(ToolBar ...

  6. delphi 控件大全(确实很全)

    delphi 控件查询:http://www.torry.net/ http://www.jrsoftware.org Tb97 最有名的工具条(ToolBar)控件库,仿Office97,如TDoC ...

  7. Winform开发框架之客户关系管理系统(CRM)的开发总结系列4-Tab控件页面的动态加载

    在前面介绍的几篇关于CRM系统的开发随笔中,里面都整合了多个页面的功能,包括多文档界面,以及客户相关信息的页面展示,这个模块就是利用DevExpress控件的XtraTabPage控件的动态加载实现的 ...

  8. GridView控件RowDataBound事件中获取列字段值的几种途径

    前台: <asp:TemplateField HeaderText="充值总额|账号余额"> <ItemTemplate> <asp:Label ID ...

  9. Ehlib(Delphi控件) v9.2.024 D7-XE10.2 免费绿色特别版

    下载地址:https://www.jb51.net/softs/579413.html#downintro2 EHLib是一个DELPHI 下的非常棒的第三方Grid控件,比DELPHI自带的强大许多 ...

随机推荐

  1. nginx gunicorn 部署flask,带参数链接不可用的现象(笔记)

    微信小程序后台,开启 gunicorn之后屏幕会输出打印结果,一旦关闭shell 带参数链接不可用,只有开启shell才能使用, 一针见血 : 注释掉所有print语句,关闭shell 带参数的链接  ...

  2. rpm梳理

  3. FM-分解机模型详解

    https://blog.csdn.net/zynash2/article/details/80029969 FM论文地址:https://www.csie.ntu.edu.tw/~b97053/pa ...

  4. springcloud流程图

    自己画的: 别人画的 别人画的2

  5. 记一次线上bug排查-quartz线程调度相关

    记一次线上bug排查,与各位共同探讨. 概述:使用quartz做的定时任务,正式生产环境有个任务延迟了1小时之久才触发.在这一小时里各种排查找不出问题,直到延迟时间结束了,该任务才珊珊触发.原因主要就 ...

  6. php生成红包

    <?php /** * 随机生成红包金额 * @param $n 红包个数 * @param $sum 总金额 整数 * @param $index_max 最大金额在数组中索引 * @para ...

  7. 求树的重心 poj 1655

    题目链接:https://vjudge.net/problem/POJ-1655 这个就是找树的重心,树的重心就是树里面找一个点,使得以这个点为树根的所有的子树中最大的子树节点数最小.题目应该讲的比较 ...

  8. TZOJ 3820 Revenge of Fibonacci(大数+trie)

    描述 The well-known Fibonacci sequence is defined as following: Here we regard n as the index of the F ...

  9. Yii2.0关闭自带的debug功能

    1.找到相应模块的config文件夹的main-local.php文件注释相关代码,如下: 2.将web下面的两个入口文件改成false  index.php  index-test.php

  10. js原生的节点操作API

    // yi获取元素节点 //一 :过id的方式( 通过id查找元素,大小写敏感,如果有多个id只找到第一个) document.getElementById('div1'); // 通过类名查找元素, ...