C1DateTime Empty

Posted by: patrick.muellner on 19 November 2024, 9:24 am EST

  • Posted 19 November 2024, 9:24 am EST

    Hi,

    I would like to know which properties I need to configure to allow the C1DateTime control to be empty.

    Additionally, how can I handle the scenario where the user presses the Delete or Backspace key, so the control becomes empty as well?

    Thank you in advance for your help!

    Best regards,

    Patrick

  • Posted 20 November 2024, 2:16 am EST

    Hello Patrick,

    This is the default behavior of C1DateEdit, and there is no direct way to override this.

    However, you can handle mouse, key, and textChanged events to set the C1DateEdit’s value back to null. Please refer to the attached sample for implementation. (see Input_DateTime.zip)

    Regards,

    Uttkarsh.

  • Posted 20 November 2024, 2:36 am EST

    Hi,

    is there a way to extend the functionality so that we have our own property, “SelectedDate”, which would eliminate the need to cast the value?

    Or is there another approach you would recommend?

    Thank you

  • Posted 20 November 2024, 8:03 am EST

    Hello Patrick,

    Yes, you can, as follows:

    public DateTime? SelectedDate 
    { 
        get
        {
            if(DateTime.TryParse(this.Text, out DateTime val))
                return val;
            return null;
        }
    }

    Please refer to the attached modified sample for the implementation. (see Input_DateTime_Mod.zip)

    PS: To avoid misunderstandings and ensure better tracking of issues, please create separate query tickets for different concerns.

    Regards,

    Uttkarsh.

  • Posted 20 November 2024, 11:23 am EST

    Hi,

    is there a straightforward way to configure a property in C1DateEdit to specify whether null values are allowed or not?

    Thank you in advance!

    Regards

  • Posted 21 November 2024, 1:16 am EST

    Hello Patrick,

    You can simply show a MessageBox if the value is null while the textbox loses focus as follows:

    protected override void OnLostFocus(EventArgs e)
    {
        if (!AllowNull && ValueIsDbNull)
        {
            MessageBox.Show("Nulls not allowed!", "MyDateEdit Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            FindForm().ActiveControl = this;
            return;
        }
    
        base.OnLostFocus(e);
    }

    Please refer to the attached modified sample for implementation. (see Input_DateTime_Mod2.zip)

    Regards,

    Uttkarsh.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels