windowsforms-devexpress-dot-xtraeditors-dot-dateedit-1b2ddde7.md
Gets or sets the edit value (current date).
Namespace : DevExpress.XtraEditors
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
public override object EditValue { get; set; }
Public Overrides Property EditValue As Object
| Type | Description |
|---|---|
| Object |
The current date.
|
The DateEdit control has the following interconnected properties that specify what value the editor stores and what text it shows to users at runtime.
(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) {
}
}
dateEdit1.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
dateEdit1.Properties.DisplayFormat.FormatString = "dd' 'MMMM', 'yyyy"
'or
AddHandler dateEdit1.FormatEditValue, AddressOf DateEdit1_FormatEditValue
private void DateEdit1_FormatEditValue(Object sender, DevExpress.XtraEditors.Controls.ConvertEditValueEventArgs e)
Try
Dim day As String = CDate(e.Value).Day.ToString()
Dim month As String = CDate(e.Value).ToString("MMMM")
Dim year As String = CDate(e.Value).Year.ToString()
e.Value = day & " " & month & ", " & year
e.Handled = True
Catch e1 As Exception
End Try
(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.
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”.
(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.
(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.
(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.
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;
}
}
Private dateEdit1.Spin += AddressOf DateEdit1_Spin
Private Sub DateEdit1_Spin(ByVal sender As Object, ByVal e As DevExpress.XtraEditors.Controls.SpinEventArgs)
Dim dateEdit As DateEdit = TryCast(sender, DateEdit)
Dim value As Date = Nothing
If Date.TryParseExact(dateEdit.Text, dateEdit.Properties.DisplayFormat.FormatString, CultureInfo.CurrentCulture, DateTimeStyles.None, value) Then
dateEdit.EditValue = value
End If
End Sub
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.
try {
dtStart.EditValue = controller.Start.Date;
dtEnd.EditValue = controller.End.Date;
else
dtEnd.EditValue = controller.DisplayEnd.Date;
}
Try
dtStart.EditValue = controller.Start.Date
dtEnd.EditValue = controller.End.Date
Else
dtEnd.EditValue = controller.DisplayEnd.Date
End If
See Also