Click here to Skip to main content
15,922,533 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: .net framework 3.5 and visual studio 2008 Pin
Luc Pattyn1-Jul-10 17:13
sitebuilderLuc Pattyn1-Jul-10 17:13 
GeneralRe: .net framework 3.5 and visual studio 2008 Pin
Dave Kreskowiak1-Jul-10 17:33
mveDave Kreskowiak1-Jul-10 17:33 
AnswerRe: .net framework 3.5 and visual studio 2008 Pin
Abhinav S29-Jun-10 4:26
Abhinav S29-Jun-10 4:26 
QuestionUser Control only for decimal and integer number Pin
milica128-Jun-10 4:41
milica128-Jun-10 4:41 
AnswerRe: User Control only for decimal and integer number Pin
Abhinav S28-Jun-10 5:13
Abhinav S28-Jun-10 5:13 
AnswerRe: User Control only for decimal and integer number Pin
Not Active28-Jun-10 5:31
mentorNot Active28-Jun-10 5:31 
GeneralRe: User Control only for decimal and integer number Pin
milica128-Jun-10 22:25
milica128-Jun-10 22:25 
AnswerRe: User Control only for decimal and integer number Pin
Roger Wright29-Jun-10 21:49
professionalRoger Wright29-Jun-10 21:49 
In Visual Basic there is a method, IsNumeric, to test whether a textbox contains a value that can be converted to a number; C# has no such method. C# does, however, include the type Decimal, which includes a Parse method. The C# Parse method will attempt to convert the text passed to it into a Decimal type, returning the Decimal value or a FormatException error. See this article[^] for information about the Decimal.Parse method.

The advantage of the Decimal type is that it can represent both integer and floating point types. You could test for all the possible real and integer types supported by C#, but that would be tedious and it's unlikely that a user will be typing an entry in a textbox large enough to require one of the more esoteric types possible. It can also be cast into other numeric types easily without loss of accuracy due to rounding errors.

If you are really trying to create a User Control containing textboxes, rather than just a textbox on a form, you can save some time by creating just one method in your control to test the validity of the input text and call it for each of your control's textboxes. That's the approach I took in [insert shameless self-promotion disclaimer] this article[^] about my first User Control. In the ValidateEntry() method, called by all of the textboxes on the User Control, I use Double.Parse() to check the values entered by the user. I don't expect any entries with integer values, so I used Double.Parse, but for your use, Decimal.Parse() is a better choice.

The MSDN article referenced above provides sample code for testing the value in VB and C#, and the samples simply display an error message if the Parse method fails. You'll probably want to do something more useful with your code. In my first User Control project, I displayed a message, set the return value to an unlikely result, then used that result to return focus to the textbox that contains the faulty data. You might want to do something else, as appropriate for your application. It's unfortunate that we don't have a method available in either language to deliver a strong electric shock to a thumb-fingered user via the keyboard but, alas, it's not a perfect world.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"

AnswerRe: User Control only for decimal and integer number Pin
PIEBALDconsult30-Jun-10 2:58
mvePIEBALDconsult30-Jun-10 2:58 
Question.Net 2.0 Applications and Windows 2008 Server Pin
sund7wells27-Jun-10 23:31
sund7wells27-Jun-10 23:31 
AnswerRe: .Net 2.0 Applications and Windows 2008 Server Pin
Not Active28-Jun-10 3:06
mentorNot Active28-Jun-10 3:06 
GeneralRe: .Net 2.0 Applications and Windows 2008 Server Pin
sund7wells28-Jun-10 18:18
sund7wells28-Jun-10 18:18 
GeneralRe: .Net 2.0 Applications and Windows 2008 Server Pin
Dave Kreskowiak28-Jun-10 18:28
mveDave Kreskowiak28-Jun-10 18:28 
QuestionRegistration form for a windows application installer Pin
arya12324-Jun-10 8:00
arya12324-Jun-10 8:00 
AnswerRe: Registration form for a windows application installer Pin
hammerstein0525-Jun-10 2:21
hammerstein0525-Jun-10 2:21 
QuestionStackOverflowException Pin
Mehdi Ghiasi24-Jun-10 6:36
Mehdi Ghiasi24-Jun-10 6:36 
AnswerRe: StackOverflowException Pin
Luc Pattyn24-Jun-10 7:28
sitebuilderLuc Pattyn24-Jun-10 7:28 
AnswerRe: StackOverflowException Pin
supercat924-Jun-10 12:31
supercat924-Jun-10 12:31 
AnswerRe: StackOverflowException Pin
Luc Pattyn25-Jun-10 9:50
sitebuilderLuc Pattyn25-Jun-10 9:50 
QuestionCrystal Report Basic Text Interpretation problem Pin
dasha_pl23-Jun-10 4:51
dasha_pl23-Jun-10 4:51 
QuestionCreate ActiveX control with .net 4.0 Pin
awu2522-Jun-10 19:05
awu2522-Jun-10 19:05 
AnswerRe: Create ActiveX control with .net 4.0 Pin
Not Active23-Jun-10 2:34
mentorNot Active23-Jun-10 2:34 
GeneralRe: Create ActiveX control with .net 4.0 Pin
awu2523-Jun-10 4:41
awu2523-Jun-10 4:41 
GeneralRe: Create ActiveX control with .net 4.0 Pin
Not Active23-Jun-10 5:22
mentorNot Active23-Jun-10 5:22 
GeneralRe: Create ActiveX control with .net 4.0 Pin
awu2523-Jun-10 16:57
awu2523-Jun-10 16:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.