0

Hi I have a numericupdown box and I am trying to load the value of it each time the form loads.

I have tried the following with no joy

   string striko1value = clsData.GetStriko1GasReading();
        decimal striko1 = decimal.Parse(striko1value);
        Striko1Numeric.Value = Convert.ToDecimal(striko1);

I have also tried this

Striko1Numeric.Value = (striko1);

Anyone have any ideas about how I would do this or where I could read up on this.

10
  • Set a breakpoint over the first line of your code. Step over that instruction (F10) and then look at the value assigned to stiko1value. Tell us what you see. Commented Oct 19, 2012 at 10:06
  • Where are you executing this code? Commented Oct 19, 2012 at 10:08
  • Did that steve before i asked the question it holds the value that i want it too. The value stays there until the Convert.ToDecimal(striko1); then it does not set the value in the numeric updown Commented Oct 19, 2012 at 10:08
  • what value your getting in "striko1" Commented Oct 19, 2012 at 10:09
  • 2
    try to hard code that and see Striko1Numeric.Maximum=100; Striko1Numeric.Minimum = 0; Striko1Numeric.Value = 10; Commented Oct 19, 2012 at 10:17

2 Answers 2

1

Supposing that your clsData.GetStriko1GasReading() effectively returns a string that can be interpreted as a decimal value, then you probably have a value that is outside the Minimum or Maximum value allowed to the NumericUpdown control

 string striko1value = clsData.GetStriko1GasReading(); 
 decimal striko1;
 if(decimal.TryParse(striko1value, out striko1))
 {
    if(striko1 > Striko1Numeric.Maximum ||  striko1 < Striko1Numeric.Minimum)
       MessageBox.Show("Value not allowed");
    else
        Striko1Numeric.Value = striko1; 
 }
 else
    MessageBox.Show("Not a valid decimal number");
Sign up to request clarification or add additional context in comments.

Comments

0

got it guys the Maximum value that i allowed was less than the value that was at striko1.

Thaks for the help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.