Skip to main content

DateEdit.DateTime Property

Gets or sets the current date/time value.

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v25.2.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[Bindable(false)]
[DXCategory("Appearance")]
public DateTime DateTime { get; set; }

Property Value

Type Description
DateTime

The current date/time value.

Remarks

The following code snippet sets the current date when a user presses Ctrl+N:

using DevExpress.XtraEditors;

dateEdit.KeyDown += DateEdit_KeyDown;

void DateEdit_KeyDown(object sender, KeyEventArgs e) {
    DateEdit control = sender as DateEdit;
    if (e.KeyCode == Keys.N && e.Control)
        control.DateTime = DateTime.Now;
}

The DateEdit exposes a set of related properties that define the edit value and the displayed text.

EditValue

The DateEdit.EditValue property stores the current value. The DateEdit control displays this value as text in the edit box.

EditValue updates only when a user selects a single date. EditValue does not change in multi-selection mode.

The DateEdit control fires the following events in response to EditValue changes:

Typing triggers multiple change cycles. Each date segment update raises the event pair:

Edit Value Changed Events - WinForms Date Edit, DevExpress

Set the DateEdit.Properties.EditValueChangedFiringMode property to Buffered to delay events until input completion.

DateTime

The DateEdit.DateTime property specifies a strongly typed DateTime value. It mirrors EditValue and ignores multiple date selection.

Do not bind the DateTime property. Bind EditValue to a data source instead.

DateOnly

The DateEdit.DateOnly property specifies a strongly typed DateOnly value. It mirrors EditValue and ignores multiple date selection.

Do not bind the DateTime property. Bind EditValue to a data source instead.

Text

The DateEdit.Text property gets the text displayed in the edit box. The control converts its EditValue to text with ToString().

Use Format Specifiers, Masks, or handle the FormatEditValue event to modify default formatting settings.

The following code snippet formats the display text as “dd MMMM, yyyy“ (for example, “22 March, 2019“):

using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;

// #1 - Use format specifiers.
dateEdit1.Properties.DisplayFormat.FormatType = FormatType.DateTime;
dateEdit1.Properties.DisplayFormat.FormatString = "dd' 'MMMM', 'yyyy";

// #2 - Use event-based formatting.
dateEdit1.FormatEditValue += DateEdit1_FormatEditValue;

void DateEdit1_FormatEditValue(object sender, ConvertEditValueEventArgs e) {
    try {
        string day = ((DateTime)e.Value).Day.ToString();
        string month = ((DateTime)e.Value).ToString("MMMM");
        string year = ((DateTime)e.Value).Year.ToString();
        e.Value = day + " " + month + ", " + year;
        e.Handled = true;
    }
    catch (Exception) {
    }
}

Synchronization

EditValue, DateTime, and DateOnly properties are synchronized. A change in one property updates other properties.

SelectedRanges

The DateEdit.SelectedRanges property stores selected date intervals. Use this property in multi-selection mode.

EditValue, DateTime, and DateOnly properties support single-date selection only. Use SelectedRanges to obtain selected dates when the SelectionMode property is set to Multiple.

The following code snippets (auto-collected from DevExpress Examples) contain references to the DateTime property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also