none
Setting up and Validating numericUpDown control for floating point numbers RRS feed

  • Question

  • Hi, I am a newbie

    I am using visual studio c# express 2008 on windows xp (home and pro)
    I am making a little program for windows xp. It has only 1 Form.
    I have a problem with numericUpDown control, I want a control that holds numbers with 2 decimal ciphers.
    Example: 1,87   -3,20    98,21    are OK. Increment must be 0.1

    1) How can I do this with numericUpDown? it can hold only decimal numbers?!?

    2) How can I validate it? with the use of double.Parse( ... ) to check if use entered a real number and then checking if the number is within the limits????

    Thanks
    Friday, January 11, 2008 4:02 PM

Answers

  • Use this in your form's load event(or somewhere where you initialize your controls):

                numericUpDown1.DecimalPlaces = 2;
                numericUpDown1.Increment = 0.1M;

    Regards
    Friday, January 11, 2008 6:56 PM

All replies

  • Use this in your form's load event(or somewhere where you initialize your controls):

                numericUpDown1.DecimalPlaces = 2;
                numericUpDown1.Increment = 0.1M;

    Regards
    Friday, January 11, 2008 6:56 PM
  •  

    Thank you the question 1 is solved.

     

    As regard the question 2 I noticed that ( I am using visual studio c# express 2008 ) :

     

    numInput.ReadOnly is false (in design view)

    the user cannot type inside chars, and that is a very good thing. This behaviour is automatic default.

    the user can type a value but after pressing enter if the value is outside the min max interval, it's reset automatically to the min or man. This is good also.

     

    So I think that many times it's not necessary to write code for validating/validated (unless you want to do some tricks).

    I googled the question of validating , I have found some people had problems, maybe they used a previous version of VS, or in Visual Basic is different.... 

     

    For example here: http://www.dotnetspider.com/qa/Question755.aspx

    the question raised is non-sense in my enviroinment, I have different behaviour than him

    Saturday, January 12, 2008 1:30 PM