TAdvDbGrid cell color works fine on screen, but in PDF output a different column is targeted


The attached picture illustrates my question.

I am applying a cell font colorizing event for a specific column in my TAdvDbGrid (red for negative values, green for positive values, otherwise gray).

It works as expected in the grid on the screen. But if I export to a PDF file, the picture shows that an entirely different column is being targeted by my GetCellColor event. The code follows, if that helps (class and function names masked out).

procedure Txxxxxxxxx.zzzzzzzGetCellColor(Sender: TObject;
ARow, ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var colTitle, valStr : string;
slDiff : single;
teamColorStr : string;
teamColorInt : integer;
begin
if ARow=0 then
begin
AFont.Style := [fsBold];
Exit;
end;

colTitle := playerStandingsDbGrid.Cells[ ACol, 0 ];

if MatchStr(colTitle, TArray.Create('Player','Team')) then
begin
AFont.Style := [fsBold];

    teamColorStr := playerStandingsDbGrid.Cells[3, ARow];

    if (colTitle='Team') and (teamColorStr<>'') then
      begin
        teamColorInt := StrToInt( teamColorStr );
        ABrush.Color := TColor( teamColorInt );
      end;
  end

else if colTitle='Start SL' then
begin
AFont.Style := [fsItalic];
end
else if colTitle='SL Diff' then
begin
valStr := playerStandingsDbGrid.Cells[ ACol, ARow ];
slDiff := StrToFloatDef( valStr, 0 );
if slDiff<0 then AFont.Color := clRed
else if slDiff>0 then AFont.Color := clGreen
else AFont.Color := clGray;
end;
end;

I retested this with the TDBAdvbGrid demo ADOEditing and I cannot reproduce this.
Code added:

procedure TForm1.DBAdvGrid1GetCellColor(Sender: TObject; ARow, ACol: Integer;
  AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var
  d: double;
begin
  if (DBAdvGrid1.Cells[ACol,0] = 'Price') and (ARow > 0) then
  begin
    d := DBAdvGrid1.Floats[ACol,ARow];
    if d > 2000000 then
      afont.Color := clRed
    else
      afont.Color := clGreen;
  end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
  advgridpdfio1.Save('e:\tms\temp\dbadvgrid.Pdf');
end;

PDF generated has price column with colors
dbadvgrid.pdf (310.1 KB)

Please compare with this modified sample.

Hopefully, replying-to an old support request will bring it back to life. (i.e., I hope you can see this.)

I am still having issues with column indexing issues in the OnGetCellColor event for TAdvDbGrid (or TAdvStringGrid) when that event is being used for PDF output. I've observed this on two computers. To help convey the issue, I wrote a test unit that you can use. I hope it can be duplicated at your end.

Below are two files for the testPdfColorsUnit: a PAS file and a text-version of the DFM file.

Note: The generated PDF and HTML files are put into the computer's temp folder, as shown in function tempFile() below.

PAS code:

unit testPdfColorsUnit;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvUtil, Vcl.Grids, AdvObj, BaseGrid,
  AdvGrid, Vcl.StdCtrls, AdvCustomComponent, AdvPDFIO, AdvGridPDFIO, HTMLText;

type
  TForm1 = class(TForm)
    AdvStringGrid1: TAdvStringGrid;
    AdvGridPDFIO1: TAdvGridPDFIO;
    cbIndex: TCheckBox;
    cbColor: TCheckBox;
    cbName: TCheckBox;
    cbOrig: TCheckBox;
    cbCurrent: TCheckBox;
    cbDiff: TCheckBox;
    pdfBtn: TButton;
    htmlBtn: TButton;
    HTMLStaticText1: THTMLStaticText;
    procedure FormCreate(Sender: TObject);
    procedure AdvStringGrid1GetCellColor(Sender: TObject; ARow, ACol: Integer;
      AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
    procedure onPdfClick(Sender: TObject);
    procedure onClickToggleCol(Sender: TObject);
    procedure onHtmlClick(Sender: TObject);
  private
    function cbStates : string;
    function tempFile( const basename:string ) : string;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses ShellApi;

{$R *.dfm}

const COLTITLE_INDEX = 'index';
      COLTITLE_COLOR = 'color';
      COLTITLE_PLAYER = 'name';
      COLTITLE_TEAM   = 'team';
      COLTITLE_ORIG   = 'orig';
      COLTITLE_CURR   = 'curr';
      COLTITLE_CHANGE = 'diff';

procedure TForm1.FormCreate(Sender: TObject);
const DUMMY_DATA : Array of String = [
        '' + COLTITLE_INDEX  + ','
           + COLTITLE_COLOR  + ','
           + COLTITLE_PLAYER + ','
           + COLTITLE_TEAM   + ','
           + COLTITLE_ORIG   + ','
           + COLTITLE_CURR   + ','
           + COLTITLE_CHANGE + '',
        '3,13299711,"Joshua",Team-Z,5.3,5.3,0',
        '65,14730722,"Fred",Team-P,7.3,7.0,-0.3',
        '87,12185009,"Ted",Team-W,5.3,5.4,0.1',
        '1,16704726,"Chris",Team-B,6.9,7,0.1',
        '69,11651309,"Steve",Team-Q,5.2,5.4,0.2',
        '8,15395583,"Conrado",Team-S,8.4,8.3,-0.1',
        '33,14155762,"William",Team-L,3.9,4,0.1'
       ];
var sList : TStringList;
   csvFile, s : string;
begin
  // Populate grid.
  sList := TStringList.Create;
  for s in DUMMY_DATA do sList.Add(s);
  csvFile := tempFile( 'sampleDataForPdfColorTesting.csv' );
  try
    sList.SaveToFile( csvFile );
    AdvStringGrid1.LoadFromCSV( csvFile );
  finally
    DeleteFile( csvFile );
    sList.Free;
  end;

  // Syncronize checkbox captions to column headers.
  cbIndex.Caption := COLTITLE_INDEX;
  cbColor.Caption := COLTITLE_COLOR;
  cbName.Caption := COLTITLE_PLAYER;
  cbOrig.Caption := COLTITLE_ORIG;
  cbCurrent.Caption := COLTITLE_CURR;
  cbDiff.Caption := COLTITLE_CHANGE;
end;

function TForm1.cbStates : string;
  function cbState( const cb : TCheckbox ) : string;
  begin
    Result := cb.Caption + '[';
    if cb.Checked then Result := Result + 'X' else Result := Result + ' ';
    Result := Result + ']  ';
  end;
begin
  Result := cbState(cbIndex)+cbState(cbColor)+cbState(cbName)+cbState(cbOrig)+cbState(cbCurrent)+cbState(cbDiff);
end;

function TForm1.tempFile( const basename:string ) : string;
var tempFolder: array[0..MAX_PATH] of Char;
begin
  GetTempPath(MAX_PATH, @tempFolder);  // trailing backslash is included here.
  Result := StrPas(tempFolder) + basename;
end;

procedure TForm1.onClickToggleCol(Sender: TObject);
var col : integer;
begin
  col := AdvStringGrid1.ColumnByHeader( (Sender as TCheckbox).Caption );

  if (Sender as TCheckbox).Checked
     then AdvStringGrid1.UnHideColumn( col )
     else AdvStringGrid1.HideColumn( col );
end;

procedure TForm1.AdvStringGrid1GetCellColor(Sender: TObject; ARow,
  ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
var colTitle, valStr : string;
    rankDiff : single;
    teamColorColIndex : integer;
    teamColorStr : string;
    teamColorInt : integer;
begin
  if ARow=0 then
     begin
       AFont.Style := [fsBold];
       Exit;
     end;

  colTitle := AdvStringGrid1.Cells[ ACol, 0 ];

  if colTitle=COLTITLE_PLAYER then
      begin
        AFont.Style := [fsBold];
      end
  else if colTitle=COLTITLE_TEAM then
      begin
        AFont.Style := [fsBold];

        teamColorColIndex := AdvStringGrid1.ColumnByHeader( COLTITLE_COLOR );
        teamColorStr := AdvStringGrid1.Cells[teamColorColIndex, ARow];
        teamColorInt := StrToInt( teamColorStr );
        ABrush.Color := TColor( teamColorInt );
      end
  else if colTitle=COLTITLE_ORIG then
      begin
        AFont.Style := [fsItalic];
      end
  else if colTitle=COLTITLE_CHANGE then
      begin
        valStr := AdvStringGrid1.Cells[ ACol, ARow ];
        rankDiff := StrToFloatDef( valStr, 0 );
             if rankDiff<0 then AFont.Color := clRed
        else if rankDiff>0 then AFont.Color := clGreen
                           else AFont.Color := clGray;
      end;
end;

procedure TForm1.onPdfClick(Sender: TObject);
var tempPdfFile : string;
begin
  tempPdfFile := tempFile( 'sampleColorTestOutput.pdf' );
  AdvGridPDFIO1.Grid := AdvStringGrid1;
  AdvGridPDFIO1.Options.Header := cbStates;
  AdvGridPDFIO1.Options.OpenInPDFReader := TRUE;
  AdvGridPDFIO1.Save( tempPdfFile );
end;

procedure TForm1.onHtmlClick(Sender: TObject);
var tempPdfFile : string;
begin
  tempPdfFile := tempFile( 'sampleColorTestOutput.html' );
  AdvStringGrid1.SaveToHtml( tempPdfFile );
  ShellExecute(Handle, nil, PChar(tempPdfFile), nil,  nil, SW_SHOWNORMAL);
end;

end.

DFM code:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 431
  ClientWidth = 814
  Color = clBtnFace
  Constraints.MinHeight = 300
  Constraints.MinWidth = 830
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  DesignSize = (
    814
    431)
  PixelsPerInch = 96
  TextHeight = 13
  object AdvStringGrid1: TAdvStringGrid
    Left = 8
    Top = 8
    Width = 798
    Height = 153
    Anchors = [akLeft, akTop, akRight, akBottom]
    DrawingStyle = gdsClassic
    FixedColor = clWhite
    TabOrder = 0
    GridLineColor = 13948116
    GridFixedLineColor = 11250603
    OnGetCellColor = AdvStringGrid1GetCellColor
    ActiveCellFont.Charset = DEFAULT_CHARSET
    ActiveCellFont.Color = 4474440
    ActiveCellFont.Height = -11
    ActiveCellFont.Name = 'Tahoma'
    ActiveCellFont.Style = [fsBold]
    ActiveCellColor = 11565130
    ActiveCellColorTo = 11565130
    BorderColor = 11250603
    ColumnSize.Stretch = True
    ColumnSize.StretchAll = True
    ControlLook.FixedGradientFrom = clWhite
    ControlLook.FixedGradientTo = clWhite
    ControlLook.FixedGradientHoverFrom = clGray
    ControlLook.FixedGradientHoverTo = clWhite
    ControlLook.FixedGradientHoverMirrorFrom = clWhite
    ControlLook.FixedGradientHoverMirrorTo = clWhite
    ControlLook.FixedGradientHoverBorder = 11645361
    ControlLook.FixedGradientDownFrom = clWhite
    ControlLook.FixedGradientDownTo = clWhite
    ControlLook.FixedGradientDownMirrorFrom = clWhite
    ControlLook.FixedGradientDownMirrorTo = clWhite
    ControlLook.FixedGradientDownBorder = 11250603
    ControlLook.DropDownHeader.Font.Charset = DEFAULT_CHARSET
    ControlLook.DropDownHeader.Font.Color = clWindowText
    ControlLook.DropDownHeader.Font.Height = -11
    ControlLook.DropDownHeader.Font.Name = 'Tahoma'
    ControlLook.DropDownHeader.Font.Style = []
    ControlLook.DropDownHeader.Visible = True
    ControlLook.DropDownHeader.Buttons = <>
    ControlLook.DropDownFooter.Font.Charset = DEFAULT_CHARSET
    ControlLook.DropDownFooter.Font.Color = clWindowText
    ControlLook.DropDownFooter.Font.Height = -11
    ControlLook.DropDownFooter.Font.Name = 'Tahoma'
    ControlLook.DropDownFooter.Font.Style = []
    ControlLook.DropDownFooter.Visible = True
    ControlLook.DropDownFooter.Buttons = <>
    Filter = <>
    FilterDropDown.Font.Charset = DEFAULT_CHARSET
    FilterDropDown.Font.Color = clWindowText
    FilterDropDown.Font.Height = -11
    FilterDropDown.Font.Name = 'Tahoma'
    FilterDropDown.Font.Style = []
    FilterDropDown.TextChecked = 'Checked'
    FilterDropDown.TextUnChecked = 'Unchecked'
    FilterDropDownClear = '(All)'
    FilterEdit.TypeNames.Strings = (
      'Starts with'
      'Ends with'
      'Contains'
      'Not contains'
      'Equal'
      'Not equal'
      'Larger than'
      'Smaller than'
      'Clear')
    FixedRowHeight = 22
    FixedFont.Charset = DEFAULT_CHARSET
    FixedFont.Color = 3881787
    FixedFont.Height = -11
    FixedFont.Name = 'Tahoma'
    FixedFont.Style = [fsBold]
    FloatFormat = '%.2f'
    HoverButtons.Buttons = <>
    HTMLSettings.ImageFolder = 'images'
    HTMLSettings.ImageBaseName = 'img'
    Look = glCustom
    PrintSettings.DateFormat = 'dd/mm/yyyy'
    PrintSettings.Font.Charset = DEFAULT_CHARSET
    PrintSettings.Font.Color = clWindowText
    PrintSettings.Font.Height = -11
    PrintSettings.Font.Name = 'Tahoma'
    PrintSettings.Font.Style = []
    PrintSettings.FixedFont.Charset = DEFAULT_CHARSET
    PrintSettings.FixedFont.Color = clWindowText
    PrintSettings.FixedFont.Height = -11
    PrintSettings.FixedFont.Name = 'Tahoma'
    PrintSettings.FixedFont.Style = []
    PrintSettings.HeaderFont.Charset = DEFAULT_CHARSET
    PrintSettings.HeaderFont.Color = clWindowText
    PrintSettings.HeaderFont.Height = -11
    PrintSettings.HeaderFont.Name = 'Tahoma'
    PrintSettings.HeaderFont.Style = []
    PrintSettings.FooterFont.Charset = DEFAULT_CHARSET
    PrintSettings.FooterFont.Color = clWindowText
    PrintSettings.FooterFont.Height = -11
    PrintSettings.FooterFont.Name = 'Tahoma'
    PrintSettings.FooterFont.Style = []
    PrintSettings.PageNumSep = '/'
    SearchFooter.ColorTo = clNone
    SearchFooter.FindNextCaption = 'Find &next'
    SearchFooter.FindPrevCaption = 'Find &previous'
    SearchFooter.Font.Charset = DEFAULT_CHARSET
    SearchFooter.Font.Color = clWindowText
    SearchFooter.Font.Height = -11
    SearchFooter.Font.Name = 'Tahoma'
    SearchFooter.Font.Style = []
    SearchFooter.HighLightCaption = 'Highlight'
    SearchFooter.HintClose = 'Close'
    SearchFooter.HintFindNext = 'Find next occurrence'
    SearchFooter.HintFindPrev = 'Find previous occurrence'
    SearchFooter.HintHighlight = 'Highlight occurrences'
    SearchFooter.MatchCaseCaption = 'Match case'
    SearchFooter.ResultFormat = '(%d of %d)'
    SelectionColor = 13744549
    ShowDesignHelper = False
    SortSettings.HeaderColor = clWhite
    SortSettings.HeaderColorTo = clWhite
    SortSettings.HeaderMirrorColor = clWhite
    SortSettings.HeaderMirrorColorTo = clWhite
    Version = '8.7.2.6'
    ColWidths = (
      64
      179
      178
      178
      178)
    RowHeights = (
      22
      22
      22
      22
      22
      22
      22
      22
      22
      22)
    object AdvGridPDFIO1: TAdvGridPDFIO
      Left = 784
      Top = 344
      Width = 26
      Height = 26
      Visible = True
      Grid = AdvStringGrid1
      Options.DefaultFont.Name = 'Arial'
      Options.Header = 'TMS PDF Header'
      Options.Footer = 'TMS PDF Footer'
      Options.Margins.Left = 20.000000000000000000
      Options.Margins.Top = 50.000000000000000000
      Options.Margins.Right = 20.000000000000000000
      Options.Margins.Bottom = 50.000000000000000000
      Options.HeaderFont.Name = 'Arial'
      Options.FooterFont.Name = 'Arial'
      Options.HeaderMargins.Left = 5.000000000000000000
      Options.HeaderMargins.Top = 5.000000000000000000
      Options.HeaderMargins.Right = 5.000000000000000000
      Options.HeaderMargins.Bottom = 5.000000000000000000
      Options.FooterMargins.Left = 5.000000000000000000
      Options.FooterMargins.Top = 5.000000000000000000
      Options.FooterMargins.Right = 5.000000000000000000
      Options.FooterMargins.Bottom = 5.000000000000000000
      Options.PageNumberMargins.Left = 10.000000000000000000
      Options.PageNumberMargins.Top = 5.000000000000000000
      Options.PageNumberMargins.Right = 10.000000000000000000
      Options.PageNumberMargins.Bottom = 5.000000000000000000
      Options.PageNumberFormat = '%d'
      Options.PageNumberFont.Name = 'Arial'
    end
  end
  object pdfBtn: TButton
    Left = 598
    Top = 400
    Width = 97
    Height = 25
    Anchors = [akRight, akBottom]
    Caption = 'PDF'
    TabOrder = 1
    OnClick = onPdfClick
  end
  object cbIndex: TCheckBox
    Left = 25
    Top = 404
    Width = 57
    Height = 17
    Anchors = [akLeft, akBottom]
    Caption = 'cbIndex'
    Checked = True
    State = cbChecked
    TabOrder = 2
    OnClick = onClickToggleCol
  end
  object cbColor: TCheckBox
    Left = 125
    Top = 404
    Width = 57
    Height = 17
    Anchors = [akLeft, akBottom]
    Caption = 'cbColor'
    Checked = True
    State = cbChecked
    TabOrder = 3
    OnClick = onClickToggleCol
  end
  object cbName: TCheckBox
    Left = 225
    Top = 404
    Width = 57
    Height = 17
    Anchors = [akLeft, akBottom]
    Caption = 'cbName'
    Checked = True
    State = cbChecked
    TabOrder = 4
    OnClick = onClickToggleCol
  end
  object cbOrig: TCheckBox
    Left = 325
    Top = 404
    Width = 57
    Height = 17
    Anchors = [akLeft, akBottom]
    Caption = 'cbOrig'
    Checked = True
    State = cbChecked
    TabOrder = 5
    OnClick = onClickToggleCol
  end
  object cbCurrent: TCheckBox
    Left = 425
    Top = 404
    Width = 68
    Height = 17
    Anchors = [akLeft, akBottom]
    Caption = 'cbCurrent'
    Checked = True
    State = cbChecked
    TabOrder = 6
    OnClick = onClickToggleCol
  end
  object cbDiff: TCheckBox
    Left = 525
    Top = 404
    Width = 44
    Height = 17
    Anchors = [akLeft, akBottom]
    Caption = 'cbDiff'
    Checked = True
    State = cbChecked
    TabOrder = 7
    OnClick = onClickToggleCol
  end
  object htmlBtn: TButton
    Left = 710
    Top = 400
    Width = 96
    Height = 25
    Anchors = [akRight, akBottom]
    Caption = 'HTML'
    TabOrder = 8
    OnClick = onHtmlClick
  end
  object HTMLStaticText1: THTMLStaticText
    Left = 8
    Top = 167
    Width = 798
    Height = 227
    Anchors = [akLeft, akRight, akBottom]
    HTMLText.Strings = (
      
        '<FONT size="10">Remove random columns by unchecking any combinat' +
        'ion of checkboxes below.  The HTML output always renders the col' +
        'umns properly, but the '
      
        '<B><FONT color="#FF0000">PDF output is unreliable</FONT></B>.  O' +
        'bserve how the colors meant for specific columns are sometimes c' +
        'orrupted in the PDF '
      'output.<br><br>'
      
        '<FONT color="#800000" bgcolor="#FFFF80">If my column indexing in' +
        ' the <B>OnGetCellColor </B>event is incorrect, then I don'#39't know' +
        ' why it works successfully on the '
      'screen and '
      
        'HTML, but not in the PDF when <U>certain columns</U> are hidden ' +
        'from the grid.</FONT>'
      '</FONT>'
      '<br><br>'
      '<u>One example</u>:<br><br>'
      '<OL><LI>Toggle off the <B>color</B> column.</LI>'
      '<LI>Click the PDF button to see the output.</LI>'
      
        '<LI>When I test it,<FONT color="#804040"> cells in the <B>name</' +
        'B> column are colored instead of in the <b>team</b> column, and ' +
        ' the coloring for the <b>diff</b> '
      'column is repeated in the <b>curr</b> collumn</FONT>.</LI>'
      
        '<LI>Now click the HTML button, and observe how <FONT color="#008' +
        '000">everything is always as expected</FONT></LI>'
      '</OL><br><br>'
      
        '<FONT color="#000080" ><I>Experiment with toggling other columns' +
        '.  Some combinations render fine in the PDF, while other combina' +
        'tions produced different '
      'results.</I></FONT>')
    TabOrder = 9
    Version = '1.6.0.0'
  end
end

Try to add your OnGetCellColor event handler also to grid.OnGetCellPrintColor

That did not work, unfortunately. I replied via email (which I'm not seeing here). Let me know if you didn't get it.

Can you please attach this as a ZIP file containing project source.
When I copy & paste your DFM put here, the IDE cannot open it.
image

testPdfColors.zip (7.2 KB)

I sent these files by direct email yesterday. But in case you meant to attached it here, see attached.

Thanks!

We could now trace & solve this issue related to using hidden columns.
The next update will address this.

Excellent news! I'm glad that I could assist in this find.

On another note, did you get me email from last week or so about a memory leak in your TAdvMemo code? Procedure TAdvCustomMemo.CursorChanged did not free TStringLists sle and sls. See your code below...

procedure TAdvCustomMemo.CursorChanged;
var
  wac, s, wstart, wend, wstartu, wendu: string;
  i, b, vp1, vp2: Integer;
  flgs, flge, foundblock: Boolean;
  es, ee: integer;
  cl,ci,ct,lc,sli,lastend: integer;
  sle,sls: TStringList;

. . . . . . . . . . 
. . . . . . . . . . 
. . . [snip]. . . . 
. . . . . . . . . . 
. . . . . . . . . . 

begin
  FCursorChangedTrigered := True;

  if Assigned(SyntaxStyles) then
  begin
    wstart := UpperCase(SyntaxStyles.BlockStart);
    wend := UpperCase(SyntaxStyles.BlockEnd);
  end;

  sls := TStringList.Create;    // MEMORY LEAK HERE
  sls.Delimiter := ',';
  sls.CommaText := wstart;

  sle := TStringList.Create;    // MEMORY LEAK HERE
  sle.Delimiter := ',';
  sle.CommaText := wend;
  lastend := $FFFF;
  foundblock := false;

  for sli := 0 to sls.Count - 1 do
  begin
. . . . . . . . . . 
. . . . . . . . . . 
. . . [snip]. . . . 
. . . . . . . . . . 
. . . . . . . . . . 
  end;

  FreeAndNil( sls ); // THIS WAS MISSING
  FreeAndNil( sle ); // THIS WAS MISSING

  if Assigned(FOnCursorChange) then
    FOnCursorChange(Self);
end;                                                            
end;

The memory leak is fixed in TMS VCL UI Pack v12.1.0.0 released yesterday.

Thanks. I saw that in the list of changes.

On another note regarding column "ACol" referencing in various TAdvStringGrid and TAdvDbGrids. When the grid has hidden columns, the events that I see issues with are:

  • OnCanClickCell
  • OnClickCell
  • OnGetCellCursor

If the hosted grid has hidden columns, then the ACol value passed into the functions are incorrect, and I've always had to manually adjust them in my code. (i.e., if I know there is a column to the left of the clicked cell is hidden, I need to increment the ACol value by one before I see which column was actually clicked. Here's an example:

procedure TMyMainForm.myDbGridCanClickCell(Sender: TObject; ARow, ACol: Integer; var Allow: Boolean);
var colTitle : string;
begin
  // Adjust ACol value to account for known hidden columns.  For this grid, we know that
  // the first two columns are hidden.  So, we have to adjust ACol before seeing what
  // colTitle we're dealing with...
  Inc( ACol, 2 );  // skip over the first 2 columns which are always hidden

  colTitle := myDbGrid.Cells[ ACol, 0 ];
  Allow := (colTitle='Team') or (colTitle='Player');
end;

The above code sample is for the OnCanClickCell event, but I need to apply the same adjustments for the OnClickCell and OnGetCellCursor events.

I tried adjusting the ACol value with some of the utility functions available, named something named like getRealCol or getDisplayCol (sorry I don't have the exact names at this moment) but those don't provide the expected column value.

The issue gets a bit more complex if other columns can be hidden on the fly (as I have demonstrated in my PDF color test program that I posted above).

If you'd like me to post this in a new topic, let me know. I can also provide another test program like I did for the PDF color test and post the source for you to compile. I'm happy to assist wherever possible.

Thanks,

Steve

You can convert grid display column to real column and vice versa with

function RealColIndex(ACol: Integer): Integer;
function DisplColIndex(ACol: Integer): Integer;

It's explained in the PDF developers guide in the part about hidden columns & rows

from page 141