首先将DBGrid1.DefaultDrawing的属性设为True。然后在DrawColumnCell事件中填写以下代码:if (PrintDM.QryQrp.FieldByName('摘要').value='本月合计') // PrintDM.QryQrp为DBGrid1的数据源 or (PrintDM.QryQrp.FieldByName('摘要').value='累计') then begin DBGrid1.Canvas.Font.Style:=[fsItalic]; if Column.FieldName ='摘要' then begin DBGrid1.Canvas.Font.Style:=[fsItalic,fsUnderLine]; //斜体、下划线 DBGrid1.Canvas.Font.Color:=clRed; //颜色:红色 end; end; DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
if (gdSelected in State) then begin DBGrid.Canvas.Brush.Color := clRed;选中为红色 DBGrid.Canvas.Font.Color := clGreen;字体为绿色 end else if (DBGrid.DataSource.DataSet.RecNo mod 2=1) then DBGrid.Canvas.Brush.Color:= clYellow;否则奇数行为黄色 else DBGrid.Canvas.Brush.Color:= clBlue;偶数行为蓝色 DBGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);
or (PrintDM.QryQrp.FieldByName('摘要').value='累计') then
begin
DBGrid1.Canvas.Font.Style:=[fsItalic];
if Column.FieldName ='摘要' then
begin
DBGrid1.Canvas.Font.Style:=[fsItalic,fsUnderLine]; //斜体、下划线
DBGrid1.Canvas.Font.Color:=clRed; //颜色:红色
end;
end;
DBGrid1.DefaultDrawColumnCell(rect,datacol,column,state);
begin
DBGrid.Canvas.Brush.Color := clRed;选中为红色
DBGrid.Canvas.Font.Color := clGreen;字体为绿色
end
else
if (DBGrid.DataSource.DataSet.RecNo mod 2=1) then
DBGrid.Canvas.Brush.Color:= clYellow;否则奇数行为黄色
else
DBGrid.Canvas.Brush.Color:= clBlue;偶数行为蓝色
DBGrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);