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
370
UltraDateTimeEditor caret default position in edit mode
posted

Hi, onto a form I’ve an UltraDateTimeEditor with the following MaskInput: {date} {time}.

When the user click over the spin button by default the control enter in edit mode with the caret positioned to the most left position. So if we have the “en-US” culture set, the control increment/decrement the month. If we have the “it-IT” (Italian) culture then the first value is the day of the month. And, of course, moving the caret we want to control others date time parts.

By default we wish to increment/decrement always the day of month regardless the system culture.

How we can accordingly  move the caret when the edit mode start?

Thanks in advance.

 

Diego.

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi Diego,

    I tried this out and I am not getting the results you describe.

    The first time I enter the UltraDateTimeEditor control, all of the text in the control is selected and when I use the spin buttons, this increments the year, not the month.

    If I place the cursor anywhere else in the control, then the next time I come back to it, the cursor is in the same place.

    But ignoring all of that, you can set the position of the cursor and the selection in the UltraDateTimeEditor in the same way you would for a TextBox - using the SelectionStart and SelectionLength properties.So for "en-US" you could do this:


            private void ultraDateTimeEditor1_Enter(object sender, EventArgs e)
            {
                ultraDateTimeEditor1.SelectionStart = 3;
                ultraDateTimeEditor1.SelectionLength = 2;
            }

    I'm afraid I don't see a way to make a generic solution for all cultures, though. The control does not expose any specific information about the different sections, so there's no way to determine the location of the month section.

    I suppose you could get the Short Date information from the current culture and parse the string yourself to find the "mm" in it - assuming that all cultures use "mm" for the month, which I am not sure is the case.

Children