|
楼主 |
发表于 2004-12-21 10:37:07
|
显示全部楼层
如何实现DataGrid分组不显示字段的名称、修改字段大小和背景等
1、分组不显示字段的名称,参考代码示例如下:
procedure TMainForm.DataGrid1CustomDrawCell(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; ANode: TTreeListNode; AColumn: TTreeListColumn;
ASelected, AFocused, ANewItemRow: Boolean; var AText: string; var AColor: Integer;
AFont: TFont; var AAlignment: TAlignment; var ADone: Boolean);
begin
if ANode.HasChildren then
begin
AColor := $0F0E0F0;
AFont.Size := AFont.Size + 2;
AText := StringUtils.Copy(AText, StringUtils.Pos(':', AText) + 2, 10);
end;
end;
{ 说明,例如对于:开户单位 : XXX,就是从冒号后的空格开始Copy,直至结束,一般Copy的最后一个参数给个足够长的整数就行,不用自己算了,Copy会自己处理的,这里首先根据Pos找到冒号的位置,由于冒号后有个空格,所以+2。效果见附件图片}
2、字体大小和背景色,参考代码如下:
procedure TMainForm.DataGrid1CustomDrawCell(Sender: TObject; ACanvas: TCanvas;
ARect: TRect; ANode: TTreeListNode; AColumn: TTreeListColumn;
ASelected, AFocused, ANewItemRow: Boolean; var AText: string; var AColor: Integer;
AFont: TFont; var AAlignment: TAlignment; var ADone: Boolean);
begin
if ANode.HasChildren and not ANode.Selected then
begin
AColor := $0F0E0F0;
AFont.Size := AFont.Size + 4;
//AText := 'Test';
end;
end;
|
|