Search code examples
vb.netnumericupdown

NumericUpDown maximum value linked to another textbox


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


Solution

  • 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