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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Custom DateTime

Thread ID:

Created:

Updated:

Platform:

Replies:

149573 Dec 1,2019 02:36 PM UTC Dec 3,2019 08:57 AM UTC WPF 3
loading
Tags: GanttControl
Ondrej
Asked On December 1, 2019 02:36 PM UTC

Hi,

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

Thanks

Ondřej Rada

Rachel A [Syncfusion]
Replied On 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. 


Ondrej
Replied On December 3, 2019 08:54 AM UTC

It's working fine now. 

Thanks

 Ondřej Rada


Rachel A [Syncfusion]
Replied On December 3, 2019 08:57 AM UTC

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon