Search code examples
c#wpfsyncfusion

Syncfusion : unnecessary Date format in print preview in WPF


I'm working with a Syncfusion SFDatagrid in WPF and I want to show date on the string format.

var col = new CustomGridTextColumn();
col.HeaderText = ReportSourceDataTable.Columns[i].ToString();

col.DisplayBinding = new Binding(ReportSourceDataTable.Columns[i].ToString());

if (ReportSourceDataTable.Columns[i].DataType == typeof(DateTime))
{
    col.DisplayBinding.StringFormat = "MM/dd/yyyy";
}

In the main application, it works fine.

enter image description here

But when I preview or export those data, then an unnecessary 'MM/dd/yyyy' string format is applied. Below are examples from a print preview

enter image description here

Can anyone tell me how I can remove this unnecessary string format?


Solution

  • You can achieve your requirement to displaying the correct date format in print preview by setting the UseBindingValue in GridTextColumn like below,

    <syncfusion:GridTextColumn MappingName="OrderDate" UseBindingValue="True" DisplayBinding="{Binding Path=OrderDate,StringFormat=MM/dd/yyyy}"/> 
    

    Regards, Jai