Click here to Skip to main content
16,012,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just created a basic two NumericUpDown control in winform. These two controller do the increment and decrement of the value, like if i choose 5 in first controller the second controller automatically choose 6, the same way in decrement.

I have used this code:

VB
Private Sub NumericUpDown2_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown2.ValueChanged
       NumericUpDown2.Minimum = NumericUpDown2.Value + 1
   End Sub

   Private Sub NumericUpDown3_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown3.ValueChanged
       NumericUpDown3.Maximum = NumericUpDown3.Value - 1
   End Sub


Then when i run with F5, i got the exception error of "System.StackOverflowException occured in Project.exe file" , then when i click the Break button, it opened the Application.Designer.vb file and highlighting the code -
Me.MainForm = Global.ProjectLinked.PLGeneralSettings


Please help me..
Posted
Comments
Andy Lanng 2-Sep-15 4:32am    
System.StackOverflowException occurs when you have a recursive method, or when you cause a recursive event. Is it possible that you have a control that contains itself? This would also be a recursion. Check your code to make sure that this isn't the case.

Also, the stacktrace might be more helpful finding the root cause

1 solution

:sigh:
Look at your code.
In the ValueChanged event handler, you are changing the value of the minimum value to one greater than the current value - so that causes the control to change the value so it fits in the new limits. This causes another ValueChanged event to fire, where you...change the value again, causing another ValueChanged event, where you...
This continues until your app ruins out of space and falls over.


Don't do that. It's silly.
 
Share this answer
 
Comments
Member 11927641 2-Sep-15 4:42am    
OMG... thanks for the advice.. I am a sh*t noob so i didn't knew that issues. Is there any tutorial to do the same without type of problem because i didn't find the same anywhere.?
OriginalGriff 2-Sep-15 5:03am    
No - you can't do that because it's logically silly! You are trying to set the Value property outside the range of valid values, and the control won't let you do that. That's part of the reason for using a NumericUpDown control - the Value is always valid and within range.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900