最新消息:

Delphi中CxGrid控件使用总结

编程 eben 1024浏览 0评论

(注版本为DevExpr_v46)

1.     CxGrid汇总功能

① OptionsView-Footer设置为True,显示页脚   ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义单个汇总,Default For Groups定义按组汇总。OptionsView-GroupFooters设置为gfAlwaysVisible则显示按组汇总。设置后界面如图。

Delphi中CxGrid控件使用总结-1

Delphi中CxGrid控件使用总结-2

2.       CxGrid的样式设置

当设置了Kind时,NativeStyle必须设置为False,如果指定了SkinName则Kind属性失效。

Delphi中CxGrid控件使用总结-3

下图是设置skinname为MoneyTwins后效果

Delphi中CxGrid控件使用总结-4

3.       导入各种格式

procedure TForm1.btn1Click(Sender: TObject);

begin

cxGridExportLink.ExportGridToHTML(‘d: est.html’,cxgrd1);

cxGridExportLink.ExportGridToXML(‘d: est.xml’,cxgrd1);

cxGridExportLink.ExportGridToExcel(‘d: est.xls’,cxgrd1);

cxGridExportLink.ExportGridToText(‘d: est.txt’,cxgrd1);

end;

4.       取某个单元格的值

Cxgrid.DataController.Values[i,j]

5.       列操作,选择CxGrid控件后,点击“Customize”新建一列,在Columns集合中选中新建的列,选择propertites属性可以设置该列的显示形式。下面介绍常用的几个

①     Properties选择CheckBox,则该列显示一个复选框,如下:

Delphi中CxGrid控件使用总结-5

判断是否选中 if  Cxgrid.DataController.Values[i,j]=’1’   选中

②     Properties选择ButtonEdit,并对该列的属性编辑器设置如下属性Buttons属性添加按钮项,对按钮项设置可以设置kind属性定义按钮样式;ViewStyle属性设置为vsButtonsOnly,Options-ShowEditButton设置为isebAlways。可以编写点击事件如下:

procedure TForm1.cxgrdbtblvwGrid1DBTableView1Column1PropertiesButtonClick(

Sender: TObject; AButtonIndex: Integer);

begin

ShowMessage(‘aaa’);

end;

③ImageComboBox,可以关联一个imagelist,显示图片。如下关联imagelist后效果。

Delphi中CxGrid控件使用总结-6

6.动态添加列和记录行

var

Column:   TcxGridColumn;

i:integer;

acount:integer;

begin

Column:= cxgrd1TableView1.CreateColumn;

Column.Caption   :=   ‘Test ‘;

cxgrd1TableView1.DataController.AppendRecord;

cxgrd1TableView1.DataController.Values[0,   0]   :=   ‘ABC ‘;

cxgrd1TableView1.DataController.Post;

//添加多条记录

for i:=1 to 4 do

begin

acount:=cxgrd1TableView1.DataController.RecordCount;

cxgrd1TableView1.DataController.AppendRecord;

cxgrd1TableView1.DataController.Values[acount,   0]   :=IntToStr(i*1);

cxgrd1TableView1.DataController.Post();

end;

end;

//删除记录

cxgrd1TableView1.DataController.DeleteRecord(0);

end;

好的代码像粥一样,都是用时间熬出来的

转载请注明:落伍老站长 » Delphi中CxGrid控件使用总结

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址