方法一:

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. el-tabs添加滚动条

    element-ui的el-tabs默认是没有滚动条的,可在 el-tab-pane上添加: <el-tab-pane style="height:90%;overflow-y:aut ...

  2. Myeclipse版本引发的css样式问题:头部自动生成一行代码导致样式引入不成功

    在运行新的项目之后,发现样式全部没了 利用开发者模式查看原因:是因为css样式文件的顶部自动生成了一行代码导致的 生成的代码:[genuitec-file-id="wc2-7"], ...

  3. 深入剖析GPU Early Z优化

    最近在公司群里同事发了一个UE4关于Mask材质的优化,比如在场景中有大面积的草和树的时候,可以在很大程度上提高效率.这其中的原理就是利用了GPU的特性Early Z,但是它的做法跟我最开始的理解有些 ...

  4. ReactiveX 学习笔记(24)使用 RxCpp + C++ REST SDK 调用 REST API

    JSON : Placeholder JSON : Placeholder (https://jsonplaceholder.typicode.com/) 是一个用于测试的 REST API 网站. ...

  5. Beta冲刺——第二天

    beat冲刺:第二天 各个成员今日完成的任务 成员 冯晓.马思远 彭辉.王爽 吴琼.郝延婷 今日完成任务 ·管理员功能模块的代码规范与测试 ·网站的前端调整 ·代码规范 ·系统管理模块功能测试 ·博客 ...

  6. Echarts 柱状图属性详解

    <script type="text/javascript"> // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init ...

  7. 【javascript知识温习】设计模式--单例模式

    var Singleton = (function(){ var instance; function init() { '; function privateMethod() { console.l ...

  8. 人人开源框架使用 renren fast

    参考地址人人开源官网: https://www.renren.io/guide/ 1.介绍 1.1.项目描述 renren-fast 是一个轻量级的 Spring Boot 快速开发平台,能快速开发项 ...

  9. python生成器(generator)、迭代器(iterator)、可迭代对象(iterable)区别

    三者联系 迭代器(iterator)是一个更抽象的概念,任何对象,如果它的类有next方法(next python3)和__iter__方法返回自己本身,即为迭代器 通常生成器是通过调用一个或多个yi ...

  10. C++中的覆盖与隐藏(详细讲解)

    C++类中覆盖与隐藏一直是一个容易理解出错的地方,接下来我就详细讲解一下区别在何处 覆盖指的是子类覆盖父类函数(被覆盖),特征是: 1.分别位于子类和父类中 2.函数名字与参数都相同 3.父类的函数是 ...