Reputation: 2060
I want to select the available value within the numeric up/down control using c#
and in general if we double click within the control then we get the following(the entire text gets selected colored Blue in BG)
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..:)
Upvotes: 2
Views: 3508
Reputation: 1104
Select
has an overload that takes two int
, one for selection start, one for selection length:
myNumericUpDown.Select(0, myNumericUpDown.Text.Length);
Upvotes: 5
Reputation: 941218
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.
Upvotes: 0
Reputation: 15227
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?
Upvotes: 1