Articles in this section
Category / Section

How to set datetime format for column when AutoGenerateColumns is true in WPF 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


Conclusion

I hope you enjoyed learning about how to disable the edit mode for certain rows based on specific condition in WPF GridDataControl.

You can refer to our WPF GridData feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF GridData documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!



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