Current Date/Time in the Gantt Chart
Details
Date:12/6/2008 7:21:55 PM
Product:ActiveGanttCSN Gantt Chart / Scheduler Component
Framework:.Net Framework 1.0
Version:2.7.3
User's Development Environment:C# Visual Studio 2008
Subject:Current Date/Time on the chart
Question

Is it possible to always display the current date/time on the chart.

The little red marker that get's displayes, and how can I update it on every second, plus how can I keep the chart always showing the little red marker, even when doing the zoom.

Answer

Answer:

Yes,

To show the Progress Line marking the current date time you have to use this code:


activeGanttCSNCtl1.CurrentViewObject.TimeLine.ProgressLine.LineType = AGCSN.E_PROGRESSLINETYPE.TLMT_USER;
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ProgressLine.Position = DateTime.Now;
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ProgressLine.Length = AGCSN.E_PROGRESSLINELENGTH.TLMA_BOTH;

In order to position the current date/time on the chart you have to use this code, even when zooming (in this example the timeline starts a month before using the DateTimeAdd function so that the progressline is visible):


activeGanttCSNCtl1.CurrentViewObject.TimeLine.ScrollBar.StartDate = DateTimeAdd("m", -1, DateTime.Now);
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ScrollBar.Interval = "1d";
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ScrollBar.SmallChange = 1;
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ScrollBar.LargeChange = 10;
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ScrollBar.Max = 400;
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ScrollBar.Enabled = true;
activeGanttCSNCtl1.CurrentViewObject.TimeLine.ScrollBar.Visible = true;

The DateTimeAdd Function used above could be as follows:


private DateTime DateTimeAdd(String Interval, int Number, DateTime dtDate)
{
    DateTime dtBuff; 
    dtBuff = new DateTime(dtDate.Year, dtDate.Month, dtDate.Day, dtDate.Hour, dtDate.Minute, dtDate.Second);
    switch (Interval)
    {
        case "s":
            return dtBuff.AddSeconds(Number);
        case "n":
            return dtBuff.AddMinutes(Number);
        case "h":
            return dtBuff.AddHours(Number);
        case "d":
            return dtBuff.AddDays(Number);
        case "w":
            return dtBuff.AddDays(Number);
        case "y":
            return dtBuff.AddDays(Number);
        case "ww":
            return dtBuff.AddDays(Number * 7);
        case "m":
            return dtBuff.AddMonths(Number);
        case "q":
            return dtBuff.AddMonths(Number * 3);
        case "yyyy":
            return dtBuff.AddYears(Number);
        default:
            return dtBuff;
    }
}

and to update it every second you use a timer:


Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );
myTimer.Interval = 1000;
myTimer.Start();

And in the elapsed event handler the following code:


public static void DisplayTimeEvent( object source, ElapsedEventArgs e )
{
      activeGanttCSNCtl1.CurrentViewObject.TimeLine.ProgressLine.Position = DateTime.Now;
      activeGanttCSNCtl1.Redraw();
}

 

All trademarks are property of their respective holders, and are only used to directly describe the products and services being provided. Their use in no way indicates any relationship or endorsement between The Source Code Store LLC and the holders of said trademarks.