关于 DBGRID,烦请各位老兄指点(100分)

W

webb

Unregistered / Unconfirmed
GUEST, unregistred user!
1.通过TQuery的'Select ...' 语句将符合条件的记录显示在DBgrid网格
> 中,如果需要将其中某字段(如:数量)>0的记录的数量以红色显示,该
> 如何实现?
> 2.在DBgrid的单元中,如果在录入字符时,使其强制转换成大写显示,该
> 如何实现?
 
1、在onDrawColumnCell 事件中
with TDbgrid(sender) do
begin
if query1.fieldbyname('数量').Asfloat>0 then
begin
Canvas.brush.Color:=clred;
DefaultDrawColumnCell(rect,datacol,column,state);
end;
end;


2、在onkeypress事件中 写 upcase(char);
 
1:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if adodataset2.Fields[0].AsInteger>10 then
begin
dbgrid1.Canvas.Font.Color:=clred;
dbgrid1.DefaultDrawDataCell(rect,column.Field,state);
end;
end;

2:
数据集中的字段 的 onsettext 事件。
 
1:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if adodataset2.Fields[0].AsInteger>10 then
begin
dbgrid1.Canvas.Font.Color:=clred;
dbgrid1.DefaultDrawDataCell(rect,column.Field,state);
end;
end;
2、在onkeypress事件中 写 upcase(char);
 
多人接受答案了。
 
顶部