$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
Data Grid WinForms Control
Create data gird view in C# with modern user interface for your Windows Forms applications
Home > WinForms UI Controls > User Manual > DateTime Column in C#

C# Grid DateTime Column

The Grid DateTime Column allows users of the Data Grid Control easily input date and time directly or select date from drop down calendar. With the Grid DateTime column, date entry and data formatting for DateTime data types are available to UI designers. To customize the grid date and time column in C#, we need to use the properties, FormatString and CustomFormat. The FormatString property is able to edit the date format and the CustomFormat is able to customize the date when users invoke the editor by clicking the cells.

Instantiate Grid DateTime Column in C#


GridDateTimeColumn dateTimeColumn = new GridDateTimeColumn();
dateTimeColumn.Name = "DateTimeColumn";
dateTimeColumn.HeaderText = "Set date";
dateTimeColumn.FieldName = "SetDate";
dateTimeColumn.FormatString = "{0:D}";

Localizing of Grid DateTime Column in C#

When we localize the grid date time column, it will be specified to a particular culture. The example of below shows how to format the date and time values and localize the grid date time column to Singapore.

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalize.Culture ("Singapore");
GridDateTimeColumn dateTimeColumn = new GridDateTimeColumn();
dateTimeColumn.Name = "DateTimeColumn";
dateTimeColumn.HeaderText = "Set date";
dateTimeColumn.FieldName = "SetDate";
dateTimeColumn.FormatString = "{0:D}";
ketticGridView1.MasterTemplate.Columns.Add(dateTimeColumn);

Format Date Column in C#

To format the date of cell of the column, we need use the edit mode and configure two properties, Format and CustomFormat. When we set the Format property to custom and change the CustomFormat property to a desired format, we can format the date and time cell of the column in C#. To access the editor of Grid DateTime Column, we will fire the CellEditorInitialized event after initialing the editor.

GridDateTimeColumn dateTimeColumn1 = new GridDateTimeColumn();
dateTimeColumn1.Name = "DateTimeColumn";
dateTimeColumn1.HeaderText = "Set date";
dateTimeColumn1.FieldName = "SetDate";
dateTimeColumn1.Format = DateTimePickerFormat.Custom;
dateTimeColumn1.CustomFormat = "t";

UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls