Solved

Delphi Custom Draw Group Cell to only affect primary group

Posted on 2013-06-07
3
808 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 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
Comment Utility
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
Comment Utility
To add to what Geert said, to detect the level just use

AViewInfo.GridRecord.Level
0
 

Author Comment

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

:)

Bianca
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now