Mega Code Archive

 
Categories / Delphi / ADO Database
 

A dbgrid looking like listpaper

Title: A dbgrid looking like listpaper Question: You want a more clearer representation of your data in a dbgrid, well reach back to the old days of long printouts produced in an hour or so by that workhorse called a matrix printer. One - maybe the only - good thing was, the listings were fairly readable, when quality listpaper was used: the kind of paper that was delivered with alternating green and white lines printed on it. Answer: How to do this in a dbgrid. It is very simple. Better than words are an example. On my mainform (MAINFORM in MAINUNIT) I have a dbgrid called SHOWGRID and a event handling function procedure Tmainform.showgridDrawColumnCell (Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with (sender as tdbgrid) do begin if DataSource.DataSet.recno mod 2 = 0 then Canvas.Brush.Color := $00F8FFC6 else Canvas.Brush.Color := clwhite; Canvas.font.Color := font.color; DefaultDrawColumnCell(Rect, DataCol, Column, State); end; end; Important: The line Canvas.font.Color := font.color; prevents, that the default Windows disabled text (clWhite) is used when a cell is selected. This method of coloring rows in a Tdbgrid works even when the dataset is filtered or sorted again and again. I tested this on a Tadoquery in Delphi 5 Remarks: In the beginning I was very content with the result. But I noticed quite a drop in performance. Especially when there are several grids active at the same time. I don't use this functionality only when an app has 1 or 2 grids active.