windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemdateedit.md
Gets or sets a value that is interpreted as the null date.
Namespace : DevExpress.XtraEditors.Repository
Assembly : DevExpress.XtraEditors.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DefaultValue(null)]
[DXCategory("Behavior")]
public virtual object NullDate { get; set; }
<DefaultValue(Nothing)>
<DXCategory("Behavior")>
Public Overridable Property NullDate As Object
| Type | Default | Description |
|---|---|---|
| Object | null |
A value interpreted as the null date.
|
The DateEdit.DateTime property (which is of the DateTime type) is in sync with the DateEdit.EditValue property (which is of the Object type).
When you set the DateTime property, the same value is assigned to the EditValue property. When you assign a value to the EditValue property, this value is converted to the DateTime type and assigned to the DateTime property.
When the EditValue property is set to null or any object that cannot be converted to a valid DateTime value, the editor’s DateTime property is set to a null date. By default, the null date is equal to DateTime.MinValue. Use the NullDate property to specify a custom null date.
When the editor’s EditValue property is set to null , DBNull , or NullDate (provided that NullDate is set to a non-default value), the editor displays the string specified by the RepositoryItem.NullText property (an empty string by default).
Note
The NullDate property is not supported when a DateEdit control is bound to a data source and the DataSourceUpdateMode.OnPropertyChanged flag is set in the corresponding Binding object.
The following example displays <empty> in grid cells with DBNull values:
using System;
using System.ComponentModel;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors.Repository;
namespace DXApplication {
public partial class Form1 : DevExpress.XtraEditors.XtraForm {
RepositoryItemDateEdit dateEditor;
public Form1() {
InitializeComponent();
InitGridControl(gridControl1);
// Bind the GridControl to runtime created data.
gridControl1.DataSource = new BindingList<DataItem>() {
new DataItem(){ Date = DateTime.Now },
new DataItem(){ Date = DBNull.Value },
new DataItem(){ Date = DBNull.Value }
};
}
void InitGridControl(GridControl grid) {
// Create and initialize the DateEdit repository item (a cell/in-place editor).
dateEditor = new RepositoryItemDateEdit() {
Name = "dateEditor",
NullDate = DBNull.Value,
NullText = "<empty>"
};
grid.RepositoryItems.Add(dateEditor);
// Create and initialize the 'Date' column.
GridColumn dateColumn = new GridColumn() {
Caption = "Date",
FieldName = "Date",
ColumnEdit = dateEditor,
Visible = true
};
(grid.MainView as GridView).Columns.Add(dateColumn);
}
}
public class DataItem {
public object Date { get; set; }
}
}
Imports System
Imports System.ComponentModel
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraEditors.Repository
Namespace DXApplication
Partial Public Class Form1
Inherits DevExpress.XtraEditors.XtraForm
Private dateEditor As RepositoryItemDateEdit
Public Sub New()
InitializeComponent()
InitGridControl(gridControl1)
' Bind the GridControl to runtime created data.
gridControl1.DataSource = New BindingList(Of DataItem)() From {
New DataItem() With {.Date = Date.Now},
New DataItem() With {.Date = DBNull.Value},
New DataItem() With {.Date = DBNull.Value}
}
End Sub
Private Sub InitGridControl(ByVal grid As GridControl)
' Create and initialize the DateEdit repository item (a cell/in-place editor).
dateEditor = New RepositoryItemDateEdit() With {
.Name = "dateEditor",
.NullDate = DBNull.Value,
.NullText = "<empty>"
}
grid.RepositoryItems.Add(dateEditor)
' Create and initialize the 'Date' column.
Dim dateColumn As New GridColumn() With {
.Caption = "Date",
.FieldName = "Date",
.ColumnEdit = dateEditor,
.Visible = True
}
TryCast(grid.MainView, GridView).Columns.Add(dateColumn)
End Sub
End Class
Public Class DataItem
Public Property Date As Object
End Class
End Namespace
See Also