Need to add dependency from GanttView

2 posts, 0 answers
  1. kanna
    kanna avatar
    28 posts
    Member since:
    Aug 2007

    Posted 10 Sep 2012 Link to this post

    I am using Silverlight Telerik GanttChart. Can you please suggest me to add the dependency to the tasks and also need to Include the tick interval Daily, Monthly,weekly based on checkboxor button click event or dropdown change event.
    Please refer my xaml and c# code as below:
    XAML code:
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/System.Windows.xaml" />
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/Telerik.Windows.Controls.xaml" />
                    <ResourceDictionary Source="/Telerik.Windows.Themes.Metro;component/Themes/Telerik.Windows.Controls.GanttView.xaml" />
        <Grid x:Name="LayoutRoot" Background="White">
            <!--<telerik:RadGanttView Name="xGanttView" HorizontalAlignment="Left" Margin="18,1,0,0" VerticalAlignment="Top" Width="Auto" />-->
            <telerik:RadGanttView x:Name="ganttview"  BorderBrush="#FFD6D4D4" Width="1000"
                    BorderThickness="1 0 1 1"
                     Grid.Row="1" Margin="0 6 0 0">
                    <telerik:ColumnDefinition MemberBinding="{Binding Title}" Header="Activities" ColumnWidth="160">
                    <telerik:ColumnDefinition MemberBinding="{Binding Start}" Header="Start" ColumnWidth="120">
                    <telerik:ColumnDefinition MemberBinding="{Binding End}" Header="End" ColumnWidth="120">
                    <telerik:ColumnDefinition MemberBinding="{Binding Duration}" Header="Duration" ColumnWidth="100">
                    <telerik:ColumnDefinition MemberBinding="{Binding Progress}" Header="Progress" ColumnWidth="100">
                    <!--<telerik:ColumnDefinition MemberBinding="{Binding IsMilestone}" Header="IsMilestone" ColumnWidth="100" />-->
    C# code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using Telerik.Windows.Controls.GanttView;
    using Telerik.Windows.Controls.Scheduling;
    using Telerik.Windows.Core;
    using System.Collections.ObjectModel;
    using SLGanttChart.WcfRef;
    using Telerik.Windows.Controls;
    namespace SLGanttChart
        public partial class MainPage : UserControl
            public static Collection<WcfRef.ProjectPlan_BO> lstProjectPlan;
            private IRangeGenerator specialSlotsGenerator;
            public static Collection<ProjectPlan> lstProject;
            private readonly static Dictionary<string, Tuple<GanttTask, string>> taskIdToGanttTask = new Dictionary<string, Tuple<GanttTask, string>>();
            private readonly static Dictionary<string, IList<string>> taskToChildren = new Dictionary<string, IList<string>>();
            private readonly static Dictionary<string, IList<string>> taskToRelation = new Dictionary<string, IList<string>>();
            public MainPage()
                Random rnd = new Random();
                this.Loaded += new RoutedEventHandler(MainPage_Loaded);
            void MainPage_Loaded(object sender, RoutedEventArgs e)
            private void LoadSampleChart()
                lstProject = new Collection<ProjectPlan>();
                ProjectPlan lstPrj = new ProjectPlan();
                lstPrj.Title = "ProjectABC";
                lstPrj.Start = Convert.ToDateTime("01/12/2012");
                lstPrj.End = Convert.ToDateTime("10/01/2012");
                lstPrj.IsDependency = false;
                lstPrj.IsMilestone = false;
                lstPrj.Duration = lstPrj.End.Subtract(lstPrj.Start);
                ProjectPlan lstPrj1 = new ProjectPlan();
                lstPrj1.Title = "Code Drop";
                lstPrj1.Start = Convert.ToDateTime("07/12/2012");
                lstPrj1.End = Convert.ToDateTime("07/12/2012");
                lstPrj1.IsDependency = true;
                lstPrj1.IsMilestone = false;
                lstPrj1.Duration = lstPrj1.End.Subtract(lstPrj1.Start);
                ProjectPlan lstPrj2 = new ProjectPlan();
                lstPrj2.Title = "ST Cycle1";
                lstPrj2.Start = Convert.ToDateTime("07/13/2012");
                lstPrj2.End = Convert.ToDateTime("08/31/2012");
                lstPrj2.IsDependency = false;
                lstPrj2.IsMilestone = false;
                lstPrj2.Duration = lstPrj2.End.Subtract(lstPrj2.Start);
                ProjectPlan lstPrj3 = new ProjectPlan();
                lstPrj3.Title = "ST Cycle2";
                lstPrj3.Start = Convert.ToDateTime("09/03/2012");
                lstPrj3.End = Convert.ToDateTime("09/29/2012");
                lstPrj3.IsDependency = false;
                lstPrj3.IsMilestone = false;
                lstPrj3.Duration = lstPrj3.End.Subtract(lstPrj3.Start);
                ProjectPlan lstPrj4 = new ProjectPlan();
                lstPrj4.Title = "ETOR Report";
                lstPrj4.Start = Convert.ToDateTime("10/01/2012");
                lstPrj4.End = Convert.ToDateTime("10/20/2012");
                lstPrj4.IsDependency = false;
                lstPrj4.IsMilestone = true;
                lstPrj4.Duration = lstPrj4.End.Subtract(lstPrj4.Start);
                DateTime dtMax = (from lst in lstProject select lst.Start).Max();
                DateTime dtMin = (from lst in lstProject select lst.End).Min();
                var d = dtMax;
                ganttview.VisibleRange = new VisibleRange(dtMin, dtMax);
                var tasks = new ObservableCollection<GanttTask>();
                var gt = new GanttTask();
                gt.UniqueId = "0";
                gt.Title = lstPrj.Title;
                gt.Start = dtMin;
                gt.End = dtMax;
                gt.Duration = dtMax.Subtract(dtMin);
                var childGT = new GanttTask();
                childGT.UniqueId = "1";
                childGT.Start = lstPrj1.Start;
                childGT.End = lstPrj1.End;
                childGT.Title = lstPrj1.Title;
                childGT.Duration = lstPrj1.End.Subtract(lstPrj1.Start);
                childGT.IsMilestone = lstPrj1.IsMilestone;
                var childGT1 = new GanttTask();
                childGT1.UniqueId = "1";
                childGT1.Start = lstPrj2.Start;
                childGT1.End = lstPrj2.End;
                childGT1.Title = lstPrj2.Title;
                childGT1.Duration = lstPrj2.End.Subtract(lstPrj2.Start);
                childGT1.IsMilestone = lstPrj2.IsMilestone;
                ganttview.TasksSource = tasks;
        public class ProjectPlan
               public string Title{get;set;}
                public DateTime Start {get;set;}
                public DateTime End { get; set; }
                public double Progress { get; set; }
                public TimeSpan Duration { get; set; }
                public string ExecutableFlag { get; set; }
                public Boolean IsMilestone { get; set; }
                public Boolean IsDependency { get; set; }

    Kannan S

  2. Ventzi
    Ventzi avatar
    114 posts

    Posted 14 Sep 2012 Link to this post

    Hi kanna,

    If you like to add a Dependency to your task, you need to create a new Dependency which property FromTask points to the related task. The following line of code demonstrates this.

    ourSecundTask.Dependencies.Add(new Dependency { FromTask = yourFirstTask });

    In your case you need to create a custom Task, because you have a additional property like ExecutableFlag. In order to create an custom task you need to inherit from GanttTask or implement IGanntTask interface. We added a sample project to illustrate how it works.

    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

Back to Top