10737 : How do I add Time items to the phGant in VCL when UseGridNotTree is true?

Question

How do I add Time items to the phGant in VCL when UseGridNotTree is true?

Answer

There are several samples in the general download that shows this.

For example the sample/VCL/Native/Project1 does it like this:

  phGant1.DateScaler.LookAndFeel:=tlfBoxed;
  phGant1.DateScaler.ScrollButtons:=tsbSmall;
  phGant1.UseGridNotTree:=TRUE;

procedure TForm1.Addrow1Click(Sender: TObject);
var
  aGridTreeNode:TphDataEntity_GridTreeNode;
  aCell:TBabCell;
begin

  if Assigned(phGant1.ActiveGantRow) then
    aGridTreeNode:=phGant1.GridNode_Add(phGant1.ActiveGantRow.GridTreeNode)
  else
    aGridTreeNode:=phGant1.GridNode_Add(nil);

  aCell:=phGant1.Grid.Cell[0,aGridTreeNode.AxisContentItem.ListIndex];
  phGant1.Grid.SetText(aCell,’a new row’);

end;

procedure TForm1.Addtimeitem1Click(Sender: TObject);
var
  aTimeItem:TphDataEntity_Ganttime;
begin
  if Assigned(phGant1.Grid.FocusedCell) then
  begin
    aTimeItem:=phGant1.GridNode_AddGantTime(phGant1.Grid.AxisContentItemToGridTreeNode(phGant1.Grid.FocusedCell.AxisContentItemY),0);
    aTimeItem.Start:=phGant1.DateScaler.Start+5;
    aTimeItem.Stop:=phGant1.DateScaler.Start+15;
    aTimeItem.Color:=Random(65000);
    aTimeItem.Style:=gtsPipe;

    aTimeItem.Row.CollisionDetection:=CBCollisionDetectOnRows.Checked;
    aTimeItem.Row.IncreaseRowHeightOnCollision_SuggestedHeightPerItem:=20;
    aTimeItem.Row.IncreaseRowHeightOnCollision:=CBIncreaseRowHeightOnCollisions.Checked;

  end;
end;

 

Leave a Reply