Link to home
Start Free TrialLog in
Avatar of Norm-al
Norm-alFlag for United States of America

asked on

Delphi Custom Draw Group Cell to only affect primary group

The below code creates a custom text group header for the date fields that I am comparing. The problem is that I usually group by primary AND secondary group, but I DO NOT WANT the below code to affect any other grouping except for the 1st level group.

Help?


procedure TfrmProdSchedule.gvProdDeliveryCustomDrawGroupCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableCellViewInfo; var ADone: Boolean);
var
  I: Integer;
  AYear, AMonth, ADay: Word;
begin
  inherited;

  for I := 0 to TcxGridDBTableView(cxGrid1Level1.GridView).ItemCount - 1 do begin   // Iterate
    // by week tag = 1
      if ((TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Properties is TcxDateEditProperties) and
         (TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Tag = cGroupByWeek)) then begin
      if VarType(AViewInfo.GridRecord.Values[I]) = varDate then begin
        AViewInfo.Text := 'Week ending: ' + DateToStr(EndOfTheWeek(TDateTime(AViewInfo.GridRecord.Values[I])));
      end else
        AViewInfo.Text := 'Week ending: (BLANK) ';
    end
    // by month tag = 2
    else
    if ((TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Properties is TcxDateEditProperties) and
        (TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Tag = cGroupByMonth)) then begin
      if VarType(AViewInfo.GridRecord.Values[I]) = varDate then  begin
        AViewInfo.Text := 'Month ending: ' + DateToStr(EndOfTheMonth(TDateTime(AViewInfo.GridRecord.Values[I])));
      end else
        AViewInfo.Text := 'Month ending: (BLANK) ';
    end
    // by quarter Tag=4
    else
    if ((TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Properties is TcxDateEditProperties) and
       (TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Tag = cGroupByQuarter)) then begin
      if VarType(AViewInfo.GridRecord.Values[I]) = varDate then
        AViewInfo.Text := 'Qtr: ' + GetDateQuarterValue(TDateTime(AViewInfo.GridRecord.Values[I]))
      else
        AViewInfo.Text := 'Qtr: (BLANK) ';
    end
    // by year Tag=3
    else
    if ((TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Properties is TcxDateEditProperties) and
        (TcxGridDBTableView(cxGrid1Level1.GridView).Items[I].Tag = cGroupByYear)) then begin
      if VarType(AViewInfo.GridRecord.Values[I]) = varDate then begin
        DecodeDate(TDateTime(AViewInfo.GridRecord.Values[I]), AYear, AMonth, ADay);
        AViewInfo.Text := 'Year: ' + IntToStr(AYear) + ' ';
      end
      else
        AViewInfo.Text := 'Year: (BLANK) ';
    end;
  end;    // for
end;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

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
To add to what Geert said, to detect the level just use

AViewInfo.GridRecord.Level
Avatar of Norm-al

ASKER

Thanks to you 2 AGAIN for solving another one of my problems :)  I really appreciate it guys!

:)

Bianca