Solved

Delphi Custom Draw Group Cell to only affect primary group

Posted on 2013-06-07
3
824 Views
Last Modified: 2013-06-10
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

0
Comment
Question by:Bianca
3 Comments
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 39231956
why a for loop on the drawing of 1 cell ?
this event gets called for every cell drawn, a for is not necessary

the AViewInfo contains the info on the cell being drawn.

the column :
AViewInfo.Item

and all the values of the record being drawn you can access by values property of this:
AViewInfo.RecordViewInfo.GridRecord

so a simple if then or case should suffice

procedure TfrmProdSchedule.gvProdDeliveryCustomDrawGroupCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableCellViewInfo; var ADone: Boolean);
var
  I: Integer;
  AYear, AMonth, ADay: Word;
  aTag: Integer;
  aType: TVarType;
  aVaue: Variant;
begin
  aTag := AViewInfo.Item.Tag;
  aValue := AViewInfo.GridRecord.Values[AViewInfo.Item.Index];
  aType := VarType(aValue);
  if aType = cGroupByWeek then 
  begin
      if aType = varDate then 
        AViewInfo.Text := 'Week ending: ' + DateToStr(EndOfTheWeek(TDateTime(AValue)))
      else
        AViewInfo.Text := 'Week ending: (BLANK) ';
   end
      // by month tag = 2
     else aTag = cGroupByMonth then 
  begin
      if aType = varDate then  
        /// etc ...

Open in new window

0
 
LVL 32

Expert Comment

by:ewangoya
ID: 39232130
To add to what Geert said, to detect the level just use

AViewInfo.GridRecord.Level
0
 

Author Comment

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

:)

Bianca
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question