Skip to main content

RepositoryItemDateEdit.NullDate Property

Gets or sets a value that is interpreted as the null date.

Namespace: DevExpress.XtraEditors.Repository

Assembly: DevExpress.XtraEditors.v24.1.dll

NuGet Package: DevExpress.Win.Navigation

Declaration

[DefaultValue(null)]
[DXCategory("Behavior")]
public virtual object NullDate { get; set; }

Property Value

Type Default Description
Object null

A value interpreted as the null date.

Remarks

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.

Example

The following example displays <empty> in grid cells with DBNull values:

WinForms Data Grid - Display Null Text in DateTime Cells

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; }
    }
}
See Also