10413 : Can I define some areas as a “break” (e.g. holiday) area?

Question

Can I define some areas as a “break” (e.g. holiday) area where I can color these areas with another color, and these areas do not allow items to be dropped (after being dragged.). These areas need to be different for each row. (e.g. Row1 – break areas are on Wednesdays; Row2 – Break areas are on Sundays and Mondays).

Answer

The GTP.NET object model does not currently contain this but as shown in the Gantt_TimeItem sample it can easily be achieved anyway;

First we define some standard time items and add our own BreakInfo object to the Userreference, then we implement the userDraw event and draw the time item and the break based on the info in our BreakInfo object.

This describes to hold break info in specific time items, if you would rather draw some information on the time item background take a look at this article: http://plexityhide.dyndns.org/InstantKB13/article.aspx?id=10278


    private void SetUpTimeItemAdvancedUserDraw()
    {
      GridNode gn=gantt1.Grid.GridStructure.RootNodes.AddNode();
      gn.GetCell(0).Content.Value="Sample of time item advanced user draw";
      GanttRow gr = GanttRow.FromGridNode(gn);
      gr.CollisionDetect=false;
      TimeItem ti1=gr.Layers[0].AddNewTimeItem();
      TimeItem ti2=gr.Layers[0].AddNewTimeItem();
      TimeItem ti3=gr.Layers[0].AddNewTimeItem();

      ti1.Start=gantt1.DateScaler.StartTime.AddDays(1);
      ti1.Stop=ti1.Start.AddDays(3);
      ti1.TimeItemLayout=new TimeItemLayout();
      ti1.TimeItemLayout.SelectHandles=Color.Black;
      ti1.TimeItemLayout.TimeItemStyle=TimeItemStyle.User;
      ti1.UserReference=new BreakInfo(1,0.5);
      
      ti2.Start=ti1.Stop.AddDays(1);
      ti2.Stop=ti2.Start.AddDays(4);
      ti2.TimeItemLayout=new TimeItemLayout();
      ti2.TimeItemLayout.SelectHandles=Color.Black;
      ti2.TimeItemLayout.TimeItemStyle=TimeItemStyle.User;
      ti2.UserReference=new BreakInfo(2,0.5);
}
private void gantt1_OnTimeItem_UserDraw(PlexityHide.GTP.Gantt aGantt, PlexityHide.GTP.TimeItemEventArgs e)
{
        if (e.TimeItem.UserReference is BreakInfo)
        {
                // I have put my own object of class BreakInfo in the UserReferenece of the time item
                // And now I retrieve it and use the information within when drawing the time item
                BreakInfo breakInfo=e.TimeItem.UserReference as BreakInfo;


                DateTime breakStart=e.TimeItem.Start.AddDays(breakInfo.startsDaysFromStart).Add(e.Diff);
                DateTime breakStop=breakStart.AddDays(breakInfo.breakLengthInDays);

                int breakStartPixel=gantt1.DateScaler.TimeToPixel(breakStart);
                int breakStopPixel=gantt1.DateScaler.TimeToPixel(breakStop);


                if (gantt1.ScheduleMode)
                {
                        e.G.FillRectangle(new SolidBrush(Color.Blue),new Rectangle(e.Rect.Left,e.Rect.Top,e.Rect.Width,breakStartPixel-e.Rect.Top));
                        e.G.FillRectangle(new SolidBrush(Color.Blue),Rectangle.FromLTRB(e.Rect.Left,breakStopPixel,e.Rect.Right,e.Rect.Bottom));
                        e.G.DrawRectangle(new Pen(Color.Black),e.Rect);
                }
                else
                {
                        e.G.FillRectangle(new SolidBrush(Color.Blue),new Rectangle(e.Rect.Left,e.Rect.Top,breakStartPixel-e.Rect.Left,e.Rect.Height));
                        e.G.FillRectangle(new SolidBrush(Color.Blue),Rectangle.FromLTRB(breakStopPixel,e.Rect.Top,e.Rect.Right,e.Rect.Bottom));
                        e.G.DrawRectangle(new Pen(Color.Black),e.Rect);
                }

        }
}

Leave a Reply