이런방법도 있습니다. 간단히 ^^
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
RH,R : Integer;
begin
RH := Rect.Bottom - Rect.Top;
R := (Rect.top div RH) - 1;
R := R mod 2;
if (R = 0) then begin
(Sender as TDbGrid).canvas.brush.Color := clInfoBk;
(Sender as TDbGrid).canvas.font.Color := clWindowText;
(Sender as TDbGrid).canvas.FillRect(Rect);
(sender as TDbGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else begin
(sender as TDbGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end ;
end;
procedure TForm1.DBGrid2DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
row : integer;
begin
with TDBGrid(Sender) do begin
row := MouseCoord(Rect.Left, Rect.Top).Y;
if ( row mod 2)=0 then begin
Canvas.Brush.Color :=clBlack;
Canvas.Font.Color:=clWhite;
end
else begin
Canvas.Brush.Color :=clWhite;
Canvas.Font.Color:=clBlack;
end;
DefaultDrawColumnCell(Rect, DataCol, Column,[]);
end;
end;
procedure TForm1.WndProc(var Message: TMessage);
begin
if (Message.Msg = WM_HSCROLL) or (Message.Msg = WM_VSCROLL) then
begin
DBGrid2.Repaint;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
RH,R : Integer;
begin
RH := Rect.Bottom - Rect.Top;
R := (Rect.top div RH) - 1;
R := R mod 2;
if (R = 0) then begin
(Sender as TDbGrid).canvas.brush.Color := clInfoBk;
(Sender as TDbGrid).canvas.font.Color := clWindowText;
(Sender as TDbGrid).canvas.FillRect(Rect);
(sender as TDbGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else begin
(sender as TDbGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end ;
end;