Calendar for WinForms | ComponentOne
DateEdit / Null Value Support
In This Topic
    Null Value Support
    In This Topic

    Null values can be difficult to handle without appropriate rules or settings. However, DateEdit provides flexible rules for handling null values and controlling relevant aspects in a variety of cases.

    In edit mode

    This is default mode of DateEditor. In edit mode (when ReadOnly is false), DateEdit allows displaying null values by setting the NullText property of EditFormat.

    In ReadOnly mode

    The DateEdit control allows displaying null values through the NullText property of DisplayFormat when the control is in ReadOnly mode. It is possible to override the NullText property in DisplayFormat to display watermark in the DateEdit control.

    In both modes, it is possible to display empty strings by setting the EmptyAsNull property to true. When editing date time values in DateEdit with DateTimeInput set to true, the control appears empty representing the null value. As you start editing values in control, the control turns to the last non-null value assigned to it or today’s date.

    The following image shows DateEdit displaying null text in the ReadOnly mode.

    The following code snippet shows how to show null text in DateEdit in ReadOnly mode.

    C#
    Copy Code
    //set calendar pop-up as ReadOnly
    dateEdit.ReadOnly = true;
    // display null text in DateEdit
    dateEdit.DisplayFormat.NullText = "No data is selected";
    
    Note: The ReadOnly property is only available for the DateEdit control in .NET 4.5.2 framework.