[Solved] Datetime change format when convert datatable to dynamic datatable ?

From this post: https://help.syncfusion.com/windowsforms/datagrid/search
I lost the format (initially its value was 5/3/20xx) after converting datatable -> dynamic datatable then binding datasouce,  I lost the origin format (it became 5/3 / 20xx hh:mm:ss)
How do i avoid this?

3 Replies

VS Vijayarasan Sivanandham Syncfusion Team April 30, 2020 01:35 PM UTC

Hi Khanh Dang,

Thank you for contacting Syncfusion support.

Your requirement can be achieved by set ShortDate value in Pattern property in GridDateTimeColumn. It can be applied in SfDataGrid two ways,

1.AutoGenerateColumn as true
           In this case SfDataGrid column generated automatically.So you can set the pattern in AutoGeneratingColumn event in SfDataGrid. Please refer the following code snippet,
 
this.sfDataGrid1.AutoGeneratingColumn += SfDataGrid1_AutoGeneratingColumn; 
 
private void SfDataGrid1_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e) 
{ 
                if (e.Column.MappingName == "OrdeDate") 
                { 
                    if (e.Column is GridDateTimeColumn) 
                    { 
                        e.Column = new GridDateTimeColumn() { MappingName = "OrdeDate", HeaderText = "Order Date", Pattern = Syncfusion.WinForms.Input.Enums.DateTimePattern.ShortDate }; 
                    } 
                } 
} 
  
2. AutoGenerateColumn as False
           In this case SfDataGrid Columns are define in manually you can set ShortDate as Pattern property GridDatetimeColumn.Please refer the below code snippet,
 
this.sfDataGrid1.Columns.Add(new GridDateTimeColumn() 
{ 
                MappingName = "OrderDate", 
                HeaderText = "Order Date", 
                Pattern = Syncfusion.WinForms.Input.Enums.DateTimePattern.ShortDate 
}); 
Regards,
Vijayarasan S



TG The GridLock April 30, 2020 05:09 PM UTC

Hi Vijayarasan,
Unfortunately my source data is dynamic data, I don't know its format in advance. I will refer to your 2 ways to solve it coming.
Thanks you!


MA Mohanram Anbukkarasu Syncfusion Team May 1, 2020 09:53 AM UTC

Hi Khanh, 

Thanks for the update. 

We will wait to hear from you. 

Regards, 
Mohanram A.  


Loader.
Up arrow icon