Identifying column in OnDrawCell procedure

I'm trying to customize a wwDBGrid - the grid is attached to an ADO Dataset retrieving records from a stored procedure.  There's no DrawColumnCell procedure in the grid, but surely there must be an alternative?
Specifically I want to display a bitmap beside a field based on criteria, but only for one column.  Everything works fine, I just can't narrow it down to a single column.

Regards,
Bob
patelkalp_aAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RickJConnect With a Mentor Commented:
In the OnDrawDataCell event you need to check the field parameter, like this

if Field = mytablefield2 then
    dbgDbGrid1.Canvas.Font.Color := clRed;
dbgDbGrid1.DefaultDrawDataCell(Rect, Field, State);
0
 
RickJCommented:
The infopower grid has a selectedfield property. Would this work for you? example

if mygrid.selectedfield = mytablefield then
  docustompainting ;
0
 
RickJCommented:
Sorry think I misread the question.
I think the ondrawdatacell will give you what you need. It has access to the field in question.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
diniludCommented:
procedure TForm1.wwDBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
0
 
patelkalp_aAuthor Commented:
My apologies, it was indeed the OnDrawDataCell procedure.
I've tried most of the properties, including selectedfield.  The fieldname never changes from that of column[0], despite the underlying value of the field being presented accurately.

In this code snippet found will never be turned on:

procedure TfMain.dbgCMS_DSPSRCMEMBERSDrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
var
  Found: Boolean;

begin
  if dbgDbGrid1.SelectedField.FieldName = 'FIELD2' then
  begin
     Found = True;
  end;
end;

  object dbgDbGrid1: TwwDBGrid
    Left = 296
    Top = 176
    Width = 377
    Height = 257
    DisableThemesInTitle = False
    Selected.Strings = (
      'FIELD1'#9'14'#9'Field 1 Desc'
      'FIELD2'#9'50'#9'Field 2 Desc'#9'F')
    IniAttributes.Delimiter = ';;'
    TitleColor = clBtnFace
    FixedCols = 0
    ShowHorzScrollBar = True
    DataSource = fData.dsDbGrid1
    Options = [dgAlwaysShowEditor, dgTitles, dgColLines, dgRowLines, dgRowSelect, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgWordWrap]
    ParentShowHint = False
    ShowHint = False
    TabOrder = 2
    TitleAlignment = taLeftJustify
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
    TitleLines = 1
    TitleButtons = False
0
 
RickJCommented:
Thanks, glad I could help.
0
All Courses

From novice to tech pro — start learning today.