在DBGRID中,能否显示复选字段,如何做?(20分)

  • 主题发起人 主题发起人 li_cj
  • 开始时间 开始时间
L

li_cj

Unregistered / Unconfirmed
GUEST, unregistred user!
在DBGRID中,能否显示复选字段,如何做?
如某一字段为boolean类型,为true显示一对号,为false时显示为空的。
 
字是“对号”和 “叉号”也行!
有人知道怎么做吗?
 
用第三方控件ehlib中的dbgrideh。
www.playicq.com中有下的
 
to mlzhou
对,我这是用这种效果。
如果不用第三方控件可以吗?
 
也行,不过比较麻烦。在OnDrawDataCell事件中写代码。动态生成checkbox控件就可以了。
 
用数据源控制,如果是检索出的结果在sql中加入:
xx=case boolean of
when true then '√'
else '×'
end
或者干脆用计算字段
 
也可以在字段的ongettext中做:
if displaytext then
if fieldbyname('aaa').asboolean then
text := '√'
else
text := '×';
 
可以在数据集的select语句里做,例如(oracle):
Select Decode(field1,1,'√','×') As aa from table1;
不过这样的话这个数据集就不能更新了。
 
在dbgrid中显示图象的例子,
你可以改一下,原理是一样的
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Bmp: TBitmap;
OutRect: TRect;
BmpWidth: Integer;
begin
// default output rectangle
OutRect := Rect;

if Column.Field = Table1Common_Name then
begin
// draw the image
Bmp := TBitmap.Create;
try
Bmp.Assign (Table1Graphic);
BmpWidth := (Rect.Bottom - Rect.Top) * 2;
OutRect.Right := Rect.Left + BmpWidth;
DBGrid1.Canvas.StretchDraw (OutRect, Bmp);
finally
Bmp.Free;
end;
// reset output rectangle, leaving space for the graphic
OutRect := Rect;
OutRect.Left := OutRect.Left + BmpWidth;
end;

// red font color if length > 100
if (Column.Field = Table1Lengthcm) and
(Table1Lengthcm.AsInteger > 100) then
DBGrid1.Canvas.Font.Color := clRed;

// default drawing
DBGrid1.DefaultDrawDataCell (OutRect, Column.Field, State);
end;
 
多人接受答案了。
 
后退
顶部