Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
AutoFillTime with 00:00
posted

Hi,

there is a very useful property "AutoFillDate" on the xamDateTimeEditor. How could we accomplish to automatically fill in "00:00" for the time? The user needs to be able to just type e. g. "11.07." and gets the year filled in (AutoFillDate=Year works fine) and also the time "00:00" when he leaves the editor.

Thanks

Ingo

  • 6365
    Verified Answer
    Offline posted

    Hello Ingo,

    In order to set the time of the XamDateTimeEditor to "00:00" when leaving edit mode, I can suggest you handle the EditModeEnding event of the XamDataGrid (presuming you are using the editor within a XamDataGrid) by accessing the editor's Text property and replacing the existing time separator ":" with "00:00" and concatenate the year part to the date section.

    e.Editor.Text = e.Editor.Text.Replace(e.Editor.Text.Substring(0, e.Editor.Text.LastIndexOf("/")),
                                            e.Editor.Text.Substring(0, e.Editor.Text.LastIndexOf("/")) + (DateTime.Now.Year % 100).ToString());
    e.Editor.Text = e.Editor.Text.Replace(":", "00" + ":" + "00");

    Since by the time this event is fired the XamDateTimeEditor has not committed its value, we do not have access to a DateTime instance that contains the new value. This is why we will have to manually adjust the Text property according to the desired behavior.

    I have attached a sample application that demonstrates the approach from above and you can use it as a starting point for implementing the functionality you are looking for.

    If you have any questions, please let me know.

    XamDataGrid_sampleDateTime.zip