Hallo xNighthawkx,
hab mal folgenden Code bei mir rauskopiert :
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
| procedure TForm2.DBGridKontoDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with (Sender as TDBGrid) do begin if (gdSelected in State) then begin Canvas.Font.Style := Canvas.Font.Style + [fsBold]; Canvas.Brush.Color := clBlue; Canvas.Font.Color := clWhite; end else begin Canvas.Font.Style := Canvas.Font.Style - [fsBold]; if DataSource.DataSet.RecNo mod 2 = 0 then begin Canvas.Brush.Color := clWhite end else begin Canvas.Brush.Color := clHellBlau; end; Canvas.Font.Color := clBlack; end; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left + 2, Rect.Top + 1, Column.Field.AsString); end; end; |
unschön ist, dass du nicht übergebene Eigenschaften ansprichst (Clientdataset1)
die zwingen dich jedesmal, den Code anzupassen, falls du mehrere DBGrids benutzt
also nicht rowno := Clientdataset1.RecNo sondern
rowno :=(Sender as TDBGrid).DataSource.DataSet.RecNo
hth
Torsten
Moderiert von
Narses: Delphi-Tags hinzugefügt