在数据集里面设置吧,设置一个字段的OnGetText事件为if Sender.AsInteger < 0 then Text := '0';把其它需要处理的字段都指向这个事件!
很多方法呀 确定太多就用for循环吧 for i:=... to ... do begin if(DBGrid.columns.items[i].Field.asinteger<0)then DBGrid.columss.items[i].field.asinteger:=0; end; ...自已填上初值终值,不连续的就分开来判断。
1楼正解,不过也可以用sql直接显示case...
它自己有个重绘事件onDrawDataCell procedure TForm1.DBGrid2DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); begin if uppercase(Field.FieldName)='字段名' then begin DBGrid2.Canvas.FillRect(Rect); if ADOTable1.Fieldbyname('字段名' ).value<0 then DBGrid2.Canvas.TextOut(Rect.left+2,Rect.top+2,'0 '); end; end;
确定太多就用for循环吧
for i:=... to ... do
begin
if(DBGrid.columns.items[i].Field.asinteger<0)then
DBGrid.columss.items[i].field.asinteger:=0;
end;
...自已填上初值终值,不连续的就分开来判断。
procedure TForm1.DBGrid2DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if uppercase(Field.FieldName)='字段名' then
begin
DBGrid2.Canvas.FillRect(Rect);
if ADOTable1.Fieldbyname('字段名' ).value<0 then
DBGrid2.Canvas.TextOut(Rect.left+2,Rect.top+2,'0 ');
end;
end;
谢谢各位!