We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Custom DateTime

Hi,

how to set custom datetime format in gantt control? I need change 12 to 24 hours. 

Thanks

Ondřej Rada

3 Replies

RA Rachel A Syncfusion Team December 2, 2019 11:51 AM UTC

Hi Ondrej, 
 
Greetings from Syncfusion. 
 
1)To set hour format in timescale, we can achieve the requirement by setting the CellTextFormat in GanttScheduleRowInfo and binding the row collection in CustomScheduleSource as in the below code snippet. 
 
[C#] 
 
        public MainWindow() 
        { 
            InitializeComponent(); 
            Gantt.CustomScheduleSource = GetCustomScheduleSource(); 
        } 
 
        public IList<GanttScheduleRowInfo> GetCustomScheduleSource() 
        { 
            return new List<GanttScheduleRowInfo> 
               { 
                   new GanttScheduleRowInfo 
                       { 
                           TimeUnit = TimeUnit.Days, 
                           PixelsPerUnit = 45, 
                           CellTextFormat = "dd" 
                       }, 
                    new GanttScheduleRowInfo 
                       { 
                           TimeUnit = TimeUnit.Hours, 
                           PixelsPerUnit = 30, 
                           CellTextFormat = "hh" 
                       } 
               }; 
        } 
 
 
[XAML] 
  <sync:GanttControl x:Name="Gantt" 
                               ItemsSource="{Binding TaskCollection}" 
                               ResourceCollection="{Binding ResourceCollection}" 
                               VisualStyle="Metro" ScheduleType="CustomDateTime" > 
                <sync:GanttControl.TaskAttributeMapping> 
                    <sync:TaskAttributeMapping  TaskIdMapping="TaskId" 
                                                TaskNameMapping="TaskName" 
                                                StartDateMapping="StartDate"  
                                                ChildMapping="Child"                                             
                                                FinishDateMapping="FinishDate" 
                                                DurationMapping="Duration"  
                                                MileStoneMapping="IsMileStone" 
                                                ProgressMapping="Progress" 
                                                PredecessorMapping="Predecessor" 
                                                ResourceInfoMapping="Resources"/> 
                </sync:GanttControl.TaskAttributeMapping> 
            </sync:GanttControl> 
 
 
2) To change the hour format in Gantt columns, we can achieve it by setting style in StyleInfoClass as in the below code snippet. 
 
[C#] 
   private void Gantt_Loaded(object sender, RoutedEventArgs e)  
        {  
            for(int i=0;i< Gantt.GanttGrid.InternalGrid.Columns.Count;i++)  
            {  
                var column = Gantt.GanttGrid.InternalGrid.Columns[i];  
                if (column.HeaderText == "Duration")  
                {  
                    column.StyleInfo.TimeSpanEdit.Format = "hh:mm:ss";  
                }  
                else if(column.HeaderText == "Start" || column.HeaderText == "Finish")  
                {  
                    column.StyleInfo.DateTimeEdit.DateTimePattern = Syncfusion.Windows.Shared.DateTimePattern.CustomPattern;  
                    column.StyleInfo.DateTimeEdit.CustomPattern = "MM / dd / yyyy hh:mm:ss";                     
                }  
            }  
  
            Gantt.GanttGrid.Model.ColumnWidths[4] = 180;  
            Gantt.GanttGrid.Model.ColumnWidths[3] = 180;  
       Gantt.GanttGrid.InternalGrid.InvalidateCells(); 
        }  
    }  
 
 
 
Also, find the sample to implement it in the below link. 
 
 
Thanks, 
Rachel. 



ON Ondrej December 3, 2019 08:54 AM UTC

It's working fine now. 

Thanks

 Ondřej Rada



RA Rachel A Syncfusion Team December 3, 2019 08:57 AM UTC

Hi Ondrej, 
 
Thank you for the confirmation. 
 
Regards, 
Rachel. 


Loader.
Live Chat Icon For mobile
Up arrow icon