Link to home
Start Free TrialLog in
Avatar of patelkalp_a
patelkalp_aFlag for Canada

asked on

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
Avatar of RickJ
RickJ

The infopower grid has a selectedfield property. Would this work for you? example

if mygrid.selectedfield = mytablefield then
  docustompainting ;
Sorry think I misread the question.
I think the ondrawdatacell will give you what you need. It has access to the field in question.
Avatar of dinilud
procedure TForm1.wwDBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
Avatar of patelkalp_a

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of RickJ
RickJ

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, glad I could help.