Solved

Delphi Custom Draw Group Cell to only affect primary group

Posted on 2013-06-07
3
830 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Ephraim Wangoya
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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