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
125
UltraNumericEditor - Integer - Highlight all text or Blank out default value
posted

I have a UltraNumericEditor of  NumericType Integer.The Value is 0(control default).

When the control gains focus, I want the default value of 0 to be highlighted.(Similar to what happens when we tab into a textbox).

I tried SelectAll() . SelectionStart etc: , to no avail. I tried Enter, Focus events..

Or I need to blank out the default value of 0. I couldn't find a way to do this.

I am expecting the user to enter an integer other than zero. Making Nullable true is not an option.I have been specifically asked not to do this.

Any help would be appreciated.Thanks!

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi Eliza,

    The NumericEditor behaves the same way the TextBox control does by default. If you tab into the control, it selected all of the text. If you click on the control, it will place the caret at the point you clicked. Once you have entered the control and established a SelectionStart point, subsequently tabbing into the control will remember the last position of the caret and use that instead of selecting everything. All of this is just like a TextBox.

    If you want to the control to always select the text, regardless of whether the user tabs into or clicks on it, then it's a little tricky. Calling SelectAll from AfterEnterEditMode would seem to be the obvious solution, but it doesn't work because the control enters edit mode on the MouseDown and then it positions the caret after that operation is complete. So the only way to to do this is to create some sort of delay and then select all of the text after the control's internal processing is complete.

    One easy way to do that is by using a BeginInvoke:


            private void ultraNumericEditor1_AfterEnterEditMode(object sender, EventArgs e)
            {            
                this.BeginInvoke(new MethodInvoker(this.SelectAllTextInNumericEditor));            
            }

            private void SelectAllTextInNumericEditor()
            {
                this.ultraNumericEditor1.SelectAll();
            }

Reply Children