Articles in this section
Category / Section

How to set datetime format for column when AutoGenerateColumns is true in Silverlight DataGrid?

1 min read

AutoGeneratingColumn event is trigger while SfDataGrid generates the columns when the Grid is loaded. This event receives two arguments: sender and AutoGeneratingColumnArgs. You can modify the property setting of auto generated columns by handling this event.

GridDataTimeColumn is one of the column type of SfDataGrid. It supports Pattern property. Using this property, you can set the date and time pattern to display the column values. This property is type of DataTimePattern. It is a enum type and it supports the following values,

CustomPattern: It is used to customize the DataTime Pattern.

ShortDate: It is used to set the standard ShortDate Pattern.

LongDate: It is used to set the standard LongDate Pattern.

ShortTime: It is used to set the standard ShortTime Pattern.

LongTime: It is used to set the standard LongTime Pattern.

FullDateTime: It is used to set the standard FullDateTime Pattern.

MonthDay: It is used to set the standard MonthDay Pattern.

RFC1123: It is used to set the standard RFC1123 Pattern.

ShortableDateTime: It is used to set the standard ShortableDateTime Pattern.

UniversalShortableDateTime: It is used to set the standard UniversalShortableDateTime Pattern.

YearMonth: It is used to set the standard YearMonth Pattern.

 

In the below code snippet, GridDateTimeColumn.Pattern property changed for auto generated column.

 

C#

this.datagrid.AutoGeneratingColumn += datagrid_AutoGeneratingColumn;
 
void datagrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e)
{
    if (e.Column.MappingName == "EmployeeDate")
    {
        // Setting default date and time format for EmployeeDate column
        ((e.Column) as GridDateTimeColumn).Pattern = Syncfusion.Windows.Shared.DateTimePattern.FullDateTime;
    }
}

 

Full Date and time is displayed in the EmployeeDate column based on the FullDateTime pattern.

The following screenshot displays the full date and time for EmployeeDate column.

F:\KB\Images\datatime.png

Sample Link:

WPF: DateTimePattern_of_SfDataGrid_WPF.zip
SilverLight: DateTimePattern_of_SfDataGrid_SilverLight.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied