[]
        
(Showing Draft Content)

Date-Time Cell

A date-time cell treats the cell contents as a date and time. You can customize both the input and display formats, and the input format can restrict users to entering valid dates and times only. Date-time cells are set using the DateTimeCellType class in the GrapeCity.Wpf.SpreadSheet.CellType namespace.


The following example code sets the DateTime cell type to the first column and adds blackout dates to prevent all past date entries.

C#

DateTimeCellType dt = new DateTimeCellType();
dt.BlackoutDates.AddDatesInPast();
spreadSheet1.Workbook.ActiveSheet.Columns[0].CellType = dt;
spreadSheet1.Workbook.ActiveSheet.Columns[0].ColumnWidth = 250;

VB

Dim dt As DateTimeCellType = New DateTimeCellType()
dt.BlackoutDates.AddDatesInPast()
spreadSheet1.Workbook.ActiveSheet.Columns(0).CellType = dt
spreadSheet1.Workbook.ActiveSheet.Columns(0).ColumnWidth = 250

Some of the primary date-time cell formatting is explained in the following sections.

Maximum/minimum Values

You can define the maximum and minimum date values that can be entered using the MaxDate and MinDate properties. When you set these limits, the drop-down calendar will only display valid date ranges and will prevent the selection of dates outside this range. Additionally, the spinner controls will limit the incrementing and decrementing of values within the specified date range.

Watermark

You can set the text to be displayed in an empty cell as a placeholder. The text displayed during input mode is configured via the WatermarkNull property, while the text shown in non-editing mode is set through the WatermarkDisplayNull property.

Field highlighting

By default, when a cell is in edit mode, the caret appears at the beginning of the first input field. You can determine which field initially displays the caret using the DefaultActiveFieldIndex property. Additionally, the HighlightText property allows you to select the field when the cell is in edit mode. The settings are as follows: None, Field, All.

Spin Function

The date-time cell includes a spin button that enables users to increment or decrement values conveniently. A user can adjust the value using the following methods:

  • Clicking the spin button

  • Pressing the up and down arrow keys

  • Using the mouse wheel

To enable the spin feature, set the AllowSpin property. You can also set how the spin buttons are displayed with the SpinButtonVisibility property.

The SpinMode property can be used to set whether the value is adjusted based on a field-by-field basis or for the entire cell value. The available SpinMode options are as follows:

SpinMode values

Explanation

Field

It increments or decrements the value of the field where the caret is currently positioned.

The increment value is set by the SpinIncrement property.

Value

This option increments or decrements the entire cell value regardless of the caret's position, based on the value defined in the SpinIncrementValue property.

Additionally, the SpinAllowWrap property determines whether the spin behavior can wrap when reaches the maximum or minimum limit.