Mega Code Archive

 
Categories / Delphi / Examples
 

Stringgridnohighlight

StringGrids - no Select << I am trying to do a display-only stringgrid with no cell highlighted. The first non-fixed cell is always defaulting to the "inverted" color state. I don't intend to ever let the user edit this grid, and that highlighted cell gives them the impression that they can.>> You're going to have to write an OnDrawCell Handler. It is easier than you think. Here is a sample of code that should help you get it done. procedure TForm.sgrDrawCells(Sender: TObject; Col, Row: Longint; Rect: TRect; State: TGridDrawState); var ACol: longint absolute Col; ARow: longint absolute Row; Buf: array[byte] of char; begin if State = gdFixed then Exit; with sgrGrid do begin Canvas.Font := Font; Canvas.Font.Color := clWindowText; Canvas.Brush.Color := clWindow; Canvas.FillRect(Rect); StrPCopy(Buf, Cells[ACol,ARow]); DrawText(Canvas.Handle, Buf, -1, Rect, DT_SINGLELINE or DT_VCENTER or DT_NOCLIP or DT_LEFT); end; end; - Jeff Fisher