DELPHI的DBGRID有两个难点
DELPHI的DBGRID有两个难点:
一,每行都是一个BUTTON,且CAPTION不同
二,每行不同行高,且由用户拖动而不同高的
这两点我用CXGRID全做到了
一,
procedure TForm1.cxGrid1DBTableView1Column1CustomDrawCell(
Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
www: tbutton;
i, j: integer;
begin
www:=nil;
try
for i := AViewInfo.GridView.Site.ComponentCount - 1 downto 0 do
begin
if AViewInfo.GridView.Site.Components[i] is tbutton then
begin
tbutton(AViewInfo.GridView.Site.Components[i]).Tag := -1;
if tbutton(AViewInfo.GridView.Site.Components[i]).Caption =
TcxGridDataCellViewInfo(AViewInfo).DisplayValue then
begin
www := tbutton(AViewInfo.GridView.Site.Components[i]);
end;
end;
end;
if TcxGridDataCellViewInfo(AViewInfo).Item.Caption = 'NAME' then
begin
if www = nil then
begin
www := tbutton.Create(AViewInfo.GridView.Site);
www.Visible:=false;
www.Parent := AViewInfo.GridView.Site;
www.Caption := TcxGridDataCellViewInfo(AViewInfo).DisplayValue; //inttostr(iii);
www.Tag := 1;
end;
www.SetBounds(AViewInfo.ClientBounds.Left, AViewInfo.ClientBounds.Top,
AViewInfo.ClientBounds.Right - AViewInfo.ClientBounds.Left, AViewInfo.ClientBounds.Bottom
-
AViewInfo.ClientBounds.Top);
www.Visible:=true;
end;
except
on e:exception do
begin
end
end;
end;
procedure TForm1.cxGrid1DBTableView1TopRecordIndexChanged(Sender: TObject);
var
i,j:integer;
begin
try
for i := cxgrid1.ActiveView.Site.ComponentCount - 1 downto 0 do
begin
if cxgrid1.ActiveView.Site.Components[i] is tbutton then
begin
tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := -1;
for j := 0 to TcxGridDBtableView(cxgrid1.ActiveView).ViewInfo.RecordsViewInfo.VisibleCount do
begin
if tbutton(cxgrid1.ActiveView.Site.Components[i]).Caption =
TcxGridDataRowViewInfo(TcxGridDBtableView(cxgrid1.ActiveView).ViewInfo.RecordsViewInfo.Items[j]).CellViewInfos[0].DisplayValue then
tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := 1;
end;
if tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag = -1 then
tbutton(cxgrid1.ActiveView.Site.Components[i]).Free;
end;
end;
except
end;
end;
procedure TForm1.cxGrid1DBTableView1ColumnSizeChanged(
Sender: TcxGridTableView; AColumn: TcxGridColumn);
var
i,j:integer;
begin
try
for i := cxgrid1.ActiveView.Site.ComponentCount - 1 downto 0 do
begin
if cxgrid1.ActiveView.Site.Components[i] is tbutton then
begin
tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := -1;
end;
if tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag = -1 then
tbutton(cxgrid1.ActiveView.Site.Components[i]).Free;
end;
except
end;
end;
二,
CXGRID中,只要GetCellHeight事件不为NIL,且optionsview中columnautowidth设为FALSE,即可以实现自动每行行高不同也。
如果要手工用户拖动而每行行高不同,可用下面代码
//
procedure TcxGridRowSizingObject.Init(const P: TPoint; AParams: TcxCustomGridHitTest);
var
www:tstringlist;
i,j:integer;
begin
inherited;
FRow := TcxCustomGridRow((AParams as TcxGridRowSizingEdgeHitTest).GridRecord);
if AParams.ViewInfo is tcxgridindicatorrowitemviewinfo then
begin
www:= tstringlist(tcxgridindicatorrowitemviewinfo( AParams.ViewInfo).GridView.Site.Tag);
if (www<>nil) then
begin
j:=0;
for i:=0 to www.Count-1 do
begin
if integer(www.Objects[i])=FRow.RecordIndex then
begin
www[i]:='-1';
j:=1;
break;
end;
end;
if j=0 then
www.AddObject('-1',pointer(FRow.RecordIndex));
end;
end;
end;
//
procedure TForm1.Button1Click(Sender: TObject);
var
www:tstringlist;
begin
adotable1.active := true;
www:=tstringlist.Create;
cxgrid1.ActiveView.Site.Tag:=integer(pointer(www));
end;
//
procedure TForm1.cxGrid1DBTableView1GetCellHeight(
Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
AItem: TcxCustomGridTableItem;
ACellViewInfo: TcxGridTableDataCellViewInfo; var AHeight: Integer);
var
www:tstringlist;
i,j:integer;
begin
www:=tstringlist(cxgrid1.activeview.site.tag);
if ((www<>nil) and (www.Count>0)) then
begin
j:=0;
for i:=0 to www.Count-1 do
begin
if integer(www.Objects[i])=arecord.RecordIndex then
begin
j:=strtoint(www[i]);
break;
end;
end;
if j<>0 then
begin
if j=-1 then
www[i]:=inttostr(cxGrid1DBTableView1.OptionsView.DataRowHeight);
j:=strtoint(www[i]);
aheight:=j;
///
cxGrid1DBTableView1ColumnSizeChanged(nil,nil);
end;
end;
end;
///
procedure TForm1.cxGrid1DBTableView1ColumnSizeChanged(
Sender: TcxGridTableView; AColumn: TcxGridColumn);
var
i,j:integer;
begin
try
for i := cxgrid1.ActiveView.Site.ComponentCount - 1 downto 0 do
begin
if cxgrid1.ActiveView.Site.Components[i] is tbutton then
begin
tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag := -1;
end;
if tbutton(cxgrid1.ActiveView.Site.Components[i]).Tag = -1 then
tbutton(cxgrid1.ActiveView.Site.Components[i]).Free;
end;
except
end;
end;
DELPHI的DBGRID有两个难点相关推荐
- 二维码解码程序的两大难点问题
二维码解码程序的两大难点问题 第一是如何对摄像头捕捉的PNG格式的图像数据进行解析,以及识别黑白模块的问题 第二是RS编码的纠错算法过程. 对PNG格式的解析,需要参考PNG格式的规范.识别黑白块要参 ...
- Delphi中将DBGRID中的内容输出到WORD中
这是我很久以前写的一篇文章,现在将它贴出来! 在使用DELPHI开发过程中发现网上有很多的开发朋友询问关于将DBGRID中的内容导出到一个WORD中的方法.想想可以帮帮大家,所以就自己写了一个.希望对 ...
- delphi 更改DBGrid 颜色技巧
1.根据条件更改某一单元格的颜色 [delphi] view plaincopy procedure TMainFrm.First_DGDrawColumnCell(Sender: TObject; ...
- 回合制游戏对战AI制作请重视这两个难点
游戏中的人机对战,"机"这一部分是由两个部分组成的:数值(比如bot数目.血量.命中率.技能cd.攻击力.防御力等等)和AI(人工智能,控制bot行为).很多没入行的朋友经常把这两 ...
- Delphi 读取文本文件的两种方式
用两种方式读取文本文件:文件流读取和文件变量读取 一.文件流方式 {*******************************************************} {功能:读取文本文 ...
- delphi的dbgrid控件点击title排序
procedure TfrmMain.DBGridEhTitleClick(Column: TColumnEh); var i : integer; begin for i:= 1 to DBGrid ...
- delphi DBgrid 使用大全
在DELPHI中经常用到网格控件(DBGrid)显示数据,网格控件只提供了每一行的颜色属性,但在实际应用中我们经常希望它按某一行某一项的取值不同显示不同的颜色,甚至在网格中的单位表格项中显示出图像等等 ...
- Delphi DBGrid总结
在 Delphi 语言的数据库编程中,DBGrid 是显示数据的主要手段 之一.但是 DBGrid 缺省的外观未免显得单调和缺乏创意.其实,我们完全可以在我们的程序中通过编程来达到美化DBGrid 外 ...
- DBGrid内使用CheckBox功能
Delphi内DBGrid使用CheckBox功能一般有两种方法,最简单的就是使用第三方控件,如TDBGridEh,使用非常方便,唯一的缺点就是编译出的文件大,大概要大500KB那个样子.另外一种相对 ...
最新文章
- 人们对大数据的几点误解
- shell -nginx启动脚本
- 【思维导图】新手该怎么学习C#/WPF
- 汇编语言之数据处理的2个基本问题
- 如何用python新建文件夹_用Python编写一个每天都在系统下新建一个文件夹的脚本...
- Mysql数据库存储原理
- IO复用之select、poll、epoll模型
- 快速接入 Android BLE 开发的基础框架
- strspn和strcspn妙用
- bug-箭头函数中this指向的问题
- pyqt5菜鸟教程_PyQt5教程(一)——第一个PyQt5程序
- 新闻丨智链万源受邀参加世界动物福利科学大会
- oracle财务系统表,EBS系统财务常用表和各表关联关系
- 0元参会丨第十届数据技术嘉年华精彩抢先速览
- 从哪些方面评价一款在线客服系统产品
- 系统短信验证码实现案例
- 水下SLAM论文!!!
- 大班音乐机器人反思_大班音乐活动lbrack;机器人rsqb;
- python爬取豆瓣书籍_Python 爬取豆瓣读书标签下的书籍
- 【容器云】Calico 组件架构
热门文章
- c#子线程线程中操作窗体更新的报错
- 一种zabbix server扩容改造方案
- 《淘宝网开店 SEO 推广 营销 爆款 实战200招》——1.5 开一家适合你自身发展的店铺...
- 转	Cocos2d-x3.0模版容器详解之三:cocos2d::Value
- Ranorex中利用code module对于测试数据的管理
- nagios用NsClient自定义windows监控
- WordPress永久链接 静态化教程
- iOS个人中心渐变动画、微信对话框、标签选择器、自定义导航栏、短信验证输入框等源码...
- 不仅教技能,还帮找人脉,运营研究社获1050万元Pre-A轮融资
- 怎样隐藏“滚动条”?