Question

I want to select the available value within the numeric up/down control using c#

enter image description here

and in general if we double click within the control then we get the following(the entire text gets selected colored Blue in BG)

enter image description here

Now my question is How do I achieve this pro-grammatically??


My trails so far :

Focus();

Select();

this doesn't seem to work, any help on this regard would be much appreciated, Thanks..:)

Was it helpful?

Solution

Select has an overload that takes two int, one for selection start, one for selection length:

myNumericUpDown.Select(0, myNumericUpDown.Text.Length);

OTHER TIPS

Do you not just want the .Value property of the control? Or are you trying to get it exactly the way it is formatted in the textbox?

You can get to the TextBox portion of the control through a trick, use the Controls property. Like this:

    var box = (TextBox)numericUpDown1.Controls[1];
    box.SelectAll();
    box.Focus();

This would normally be a bit fragile, but it is 99.9% guaranteed that NumericUpDown is never going to change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top