请问,怎么在DBGRID中改变CELL内容 Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiDB/html/delphi_20061216104516278.html
我写了以下代码:但是还是显示数字
procedure TMakeTicket.DBGridEh3DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
inherited;
with DBGridEh3.Canvas do
case ADOQuery2.FieldByName('status').AsInteger of
1:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('处理')) div 2,'处理');
2:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('未处理')) div 2,'未处理');
end;
DBGridEh3.DefaultDrawColumnCell(Rect, DataCol, Column, State);
}
去掉inherited试试
procedure TMakeTicket.DBGridEh3DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
begin
inherited;
if Column.FieldName = 'Status' then
begin
with DBGridEh3.Canvas do
begin
FillRect(Rect);
case ADOQuery2.FieldByName('status').AsInteger of
1:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('处理')) div 2,'处理');
2:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('未处理')) div 2,'未处理');
end;
end else
DBGridEh3.DefaultDrawColumnCell(Rect, DataCol, Column, State);
1:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('处理')) div 2,'处理');
2:TextRect(Rect,Rect.Left,((Rect.Bottom-Rect.Top)-TextHeight('未处理')) div 2,'未处理');
============可以简洁点
1:TextOout(Rect.Left, Rect.Top+2,'处理');
2:TextOout(Rect.Left, Rect.Top+2,'未处理');
1:TextOout(Rect.Left+2, Rect.Top+2,'处理');
2:TextOout(Rect.Left+2, Rect.Top+2,'未处理');