GridViewDateTimeColumn
GridViewDateTimeColumn provides date entry and formatting for DateTime data types. You may enter the date and time directly into the editor or drop down the calendar to choose a date. The FormatString property sets the format of the date when the date is not currently being edited. The CustomFormat property is used to format the date once the user clicks on the cell to invoke the editor.
Figure 1: GridViewDateTimeColumn in Edit Mode
Formatting the date.
The formatting for date and time values also responds to globalization settings.
The code below demonstrates how to change date formatting in edit mode (while the cell is being edited). There are two ways to achieve that - by setting the Format property of the column to Custom and the CustomFormat property of the column to a desired format, or by setting the same properties of the editor itself. Please note that we are using the CellEditorInitialized event which is fired when the initialization of an editor is done in order to access the editor:
If we do not use the CellEditorInitialized
, but CellBeginEdit
(it is fired before CellEditorInitialized
), our Format setting will be overridden by the initialization of the editor.
You can also change the way the dates in the column are filtered. This is how the column can be adjusted to filter only by Dates.
DateTimeKind property
This property allows you to transform the date/time values from database to the local time. By default RadGridView supposes that the date/time values are stored in UTC in the database.
Member Name | Description |
---|---|
Local | If Local is assigned to a column, in this mode, its values will first converted into Local time. |
Unspecified | Value will not converted. |
Utc | Value will not converted. |
EditorType
The EditorType allows you to easily change the editor type. It could be set to three values:
DateTimePicker: this is the default value and the editor will be a standard RadDateTimePicker.
TimePicker: the editor will be a RadTimePicker.
DateTimePickerSpinMode: this type of editor shows up/down buttons instead of a drop down with a calendar.