Table of Contents

Class DateField

Namespace
Terminal.Gui.Views
Assembly
Terminal.Gui.dll

Provides date editing functionality with specialized cursor behavior for date entry.

public class DateField : TextField, IDisposable, ISupportInitializeNotification, ISupportInitialize, IDesignable, IValue<string>, IValue<DateTime?>, IValue
Inheritance
DateField
Implements
Inherited Members

Remarks

DateField extends TextField with date-specific cursor behavior:

  • Cursor positions are constrained to valid digit positions (skipping separators)
  • Position 0 is reserved for a leading space; valid cursor range is [1, FormatLength]
  • Numeric input replaces characters in-place rather than inserting
  • Delete operations replace digits with '0' rather than removing characters

Cursor Position Model:

  • InsertionPoint: Inherited, but constrained by the override to [1, FormatLength]
  • Terminal.Gui.Views.DateField.AdjustInsertionPoint(System.Int32,System.Boolean): Adjusts cursor to skip over date separator characters
  • Terminal.Gui.Views.DateField.IncrementInsertionPoint/Terminal.Gui.Views.DateField.DecrementInsertionPoint: Move cursor while respecting separator positions

Example: For format "MM/dd/yyyy" with text " 01/15/2024":

  • Position 0: Leading space (not user-accessible)
  • Positions 1-2: Month digits (01)
  • Position 3: Separator '/' (cursor skips over)
  • Positions 4-5: Day digits (15)
  • Position 6: Separator '/' (cursor skips over)
  • Positions 7-10: Year digits (2024)

Constructors

DateField()

Initializes a new instance of DateField.

DateField(DateTime)

Initializes a new instance of DateField.

Properties

Culture

CultureInfo for date. The default is CultureInfo.CurrentCulture.

InsertionPoint

Gets or sets the cursor position within the date field, constrained to valid digit positions.

Value

Gets or sets the date value of the DateField.

Methods

DeleteCharLeft(bool)

Deletes the character to the left.

DeleteCharRight()

Deletes the character to the right.

OnKeyDownNotHandled(Key)

Called when the user has pressed key it wasn't handled by KeyDown and was not bound to a key binding.

OnMouseEvent(Mouse)

Called when a mouse event occurs within the view's Viewport.

OnValueChanged(ValueChangedEventArgs<DateTime?>)

Called when the DateField Value has changed.

OnValueChanging(ValueChangingEventArgs<DateTime?>)

Called when the DateField Value is changing.

Events

ValueChanged

Raised when Value has changed.

ValueChanging

Raised when Value is about to change. Set Handled to true to cancel the change.