Skip to main content

DateEdit.EditValue Property

Gets or sets the edit value (current date).

Namespace: DevExpress.XtraEditors

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

public override object EditValue { get; set; }

Property Value

Type Description
Object

The current date.

Remarks

The DateEdit control has the following interconnected properties that specify what value the editor stores and what text it shows to users at runtime.

Text

(the DateEdit.Text property)

A string value that is the text displayed inside the editor’s text box. Normally, this is the editor’s edit value converted to text with the ToString() method. To modify this text, use Format Specifiers and Masks, or handle the BaseEdit.FormatEditValue event.

The code sample below illustrates two ways to make the DateEdit display its text in the “dd MMMM, yyyy” format (e.g., “22 March, 2019”).

dateEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
dateEdit1.Properties.DisplayFormat.FormatString = "dd' 'MMMM', 'yyyy";

//or

dateEdit1.FormatEditValue += DateEdit1_FormatEditValue;
private void DateEdit1_FormatEditValue(object sender, DevExpress.XtraEditors.Controls.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) {
    }
}

Edit Value

(the DateEdit.EditValue property)

The value stored within the editor. Specifies the currently selected date. The editor’s text box shows the textual representation of this value.

Edit value changes only when a user selects a single date. When users select time intervals that include multiple days (see the RepositoryItemDateEdit.SelectionMode property), the edit value does not update.

When the edit value is about to change, the cancelable DateEdit.EditValueChanging event fires. If it was not cancelled and the new edit value is accepted, the DateEdit.EditValueChanged occurs afterwards. When users type text in the editor’s text box, these events fire when the focus moves from one date “portion” to another. For example, the animation below illustrates that the Changing\Changed event pair fires three times when a user edits “MM/DD/YYYY”-formatted dates.

image

You can set the DateEdit.Properties.EditValueChangedFiringMode property to Buffered to force the Changing\Changed events to fire when a user stops typing text, before they move focus to another date “portion”.

Date Time

(the DateEdit.DateTime property)

Similar to the Edit Value, stores the currently selected date and does not change when users select multiple time intervals. Returns a DateTime structure instead of an Object.

This property cannot be bound to a data source field. If you need the editor to display values from a data source, bind the EditValue property instead.

EditValue, DateTime, and DateOnly properties are synced: when either of them changes, the other property is updated as well.

Date Only

(the DateEdit.DateOnly property)

Similar to the Date Time, stores the currently selected date and does not change when users select multiple time intervals. Returns a DateOnly structure.

This property cannot be bound to a data source field. If you need the editor to display values from a data source, bind the EditValue property instead.

EditValue, DateTime, and DateOnly properties are synced: when either of them changes, the other property is updated as well.

Selected Ranges

(the DateEdit.SelectedRanges property)

Stores selected date intervals. Since EditValue, DateTime, and DateOnly properties store only single-date selection values, use this collection to get or set selected DateTime values when the RepositoryItemDateEdit.SelectionMode property is set to Multiple.

Example

The code sample below illustrates how to change a date in a date edit with mouse wheel.

dateEdit1.Spin += DateEdit1_Spin;

private void DateEdit1_Spin(object sender, DevExpress.XtraEditors.Controls.SpinEventArgs e)
{
    DateEdit dateEdit = sender as DateEdit;
    DateTime value;
    if (DateTime.TryParseExact(dateEdit.Text, dateEdit.Properties.DisplayFormat.FormatString, CultureInfo.CurrentCulture, DateTimeStyles.None, out value))
    {
        dateEdit.EditValue = value;
    }

}

The following code snippets (auto-collected from DevExpress Examples) contain references to the EditValue 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