Question NumericUpDown "selectall"?

Noremacam

Member
Joined
Jun 30, 2008
Messages
14
Programming Experience
1-3
How do I make the text(or value?) selected when I focus on the control? Textboxes have the "selectall" feature, where the NUD does not.
 

Noremacam

Member
Joined
Jun 30, 2008
Messages
14
Programming Experience
1-3
There is no text property for the NUD, but I did figure it out from your example. Thanks!

VB.NET:
nud.Select(0, nudCost.Value.Length)

However, this will not highlight extra zero's after the decimal place - which thankfully is not an issue with me.
 

Noremacam

Member
Joined
Jun 30, 2008
Messages
14
Programming Experience
1-3
That's weird because its not on my list. I included a pic to show all the members it shows for me(that begin with T). It has textalign, but not text. I'm using visual studio 2008 SP1 Express Edition - if that makes any difference.
 

Attachments

  • Notext.gif
    Notext.gif
    13.1 KB · Views: 35

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,548
Location
Norway
Programming Experience
10+
Text property is "infrastructure" and hidden.
Noremacam said:
nud.Select(0, nudCost.Value.Length)
Think you meant this:
VB.NET:
nud.Select(0, nud.[B]Value.ToString[/B].Length)
Value is the numeric value, using ToString gets the string representation displayed in control, and it's the length of the string that need to be selected. The Enter event can be used.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,502
Location
Sydney, Australia
Programming Experience
10+
The NumericUpDown DOES have a Text property. It MUST have a Text property because it is inherited from the Control class. It is hidden from Intellisense because, as JohnH says, it's not intended to be used. That doesn't mean it can't be used though, and for this it may HAVE to be used. Consider the case where you have set the DecimalPlaces property of a NUD to 2 and the current value is 1D. The control will be displaying the string "1.00" while Value.ToString will return "1". As such you'll get the wrong length and not all the text will be selected. Just use the Text property and you'll have no issues.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,548
Location
Norway
Programming Experience
10+
I actually only tested the opposite case on previous post. This can also be used:
VB.NET:
nud.Select(0, nud.Value.ToString("n" & nud.DecimalPlaces).Length)
Then there is the Hexadecimal And ThousandsSeparator properties, those cases can also be handled. Others? :)
 
Top Bottom