?
Solved

Delphi Custom Draw Group Cell to only affect primary group

Posted on 2013-06-07
3
Medium Priority
?
851 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 38

Accepted Solution

by:
Geert Gruwez earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 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