0

is there a way for the maximum value of numericUpDown linked or depends on the value of textbox labeled AB?

for example the value of textbox labeled "AB" is 10, it automatically sets the maximum value of numericUpDown to 10.

enter image description here

0

1 Answer 1

1

You can simply add an event handler for the Leave event and set the Maximum property of the NumericUpDown in that event

Sub AB_Leave(sender As Object, e As EventArgs)

    Dim value As Decimal
    ' Safety check, the user can type anything in the textbox, 
    ' we accept only a decimal number
    If Decimal.TryParse(AB.Text, value) Then
        numericUpDown1.Maximum = value
    End If
End Sub
Sign up to request clarification or add additional context in comments.

3 Comments

It works! thank you so much for the answer, now my problem is if I type on the NumericUpDown a number that is more than the value of the AB.Text, a message error should appear.
like this: If numberUpDown.value > AB.Text MsgBox ("Invalid Data", MsgBoxStyle.Critical, "Inventory System" I dont know why error does not display, it only automatically adjust the value of numericUpDown to equals the AB.Text value
I am not aware of anything ready to be used in this context. Probably you should work directly with the keyboard events like explained in this answer stackoverflow.com/questions/17369670/… but then, what about the Copy/Paste operations? As you can see it is not easy to reach this level of control without direct support from the control itself. Another possibility is to subclass the control and this is another can of worms and you should weight the costs to implement it before going forward.

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.