How to make a numericupdown control to have the range between 10-2000 in step of 10...and 2000-9900 in step of 100
the code bellow worck's, but with one bug....for eg, if i have 2000 value....and i go down...he go on 1900 value...and i want 1990(if i go up again worck's fine)
is posible to make that
i search an event ho tell'me in witch way i'm click(up or down)...but i don't find...so, please help'me. tank's
(p.s.:the value 1900 is correct...but the value 2010 is not correct....)
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumericUpDown1.ValueChanged
If NumericUpDown1.Value >= 2000 Then
NumericUpDown1.Increment = 100
End If
If NumericUpDown1.Value < 2000 Then
NumericUpDown1.Increment = 10
End If
End Sub

numericupdown problem
Fahad349
DMan1
When i go on 2000, if i go up...go 2100, but if i go down, go on 1900(an i want 1990)
Rick01
CYBORG615
Behn26
Hi!
you ask> How to make a numericupdown control to have the range between 10-2000 in step of 10...and 2000-9900 in step of 100
The first problem is your range requirements. You use 2000 as both your upper range and your lower range. They should be different. Determine where you want the lower range of the 100 delta to be. Is it ok to jump from 2010 to 1910 or do you want something more complex like a shrinking delta as you approach the 2000 line such as 2010 to 1990
Get your rules straight first. Your initial question was too simplistic. When you have determied your rules, then you can formulate a solution.
Ibrahim
bird.tw
Hi,
I don't think that ValueChanged is a good event for handling this kind of situation, because when user enters the number by typing, the default behavior is that it gets fired only when the control loses focus. I tried to make a new MyNumericUpDown control by deriving from the original one, and overriden its OnTextChanged method. Here's what I got:
Public
Class MyNumericUpDownInherits NumericUpDown
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
Dim newIncrement As Integer
Dim currentValue As Decimal = Value
If currentValue < 10 Then
newIncrement = 1
ElseIf currentValue < 2000 Then
newIncrement = 10
Else
newIncrement = 100
End If
Increment = newIncrement
End Sub
End Class
Put this in a separate file and compile it - the control should appear in your toolbox. Drag it on your form, set its Maximum property to 9900 and you're done. I hope it works for you.
You could also further extend the control by adding the ability to set value ranges with different Increment values...
Andrej
Le Saint
Miguel Jim&#38;&#35;233&#59;nez
Ok,
try overriding UpButton() and DownButton methods, you can set wanted increment value there:
Public
Class MyNumericUpDownInherits NumericUpDown
Public Overrides Sub DownButton()
Dim newIncrement As Integer
Dim currentValue As Decimal = Value
If currentValue <= 10 Then
Public Overrides Sub UpButton()newIncrement = 1
ElseIf currentValue <= 2000 Then
newIncrement = 10
Else
newIncrement = 100
End If
Increment = newIncrement
MyBase.DownButton()
End Sub
Dim newIncrement As Integer
Dim currentValue As Decimal = Value If currentValue < 10 Then
newIncrement = 1
ElseIf currentValue < 2000 Then
newIncrement = 10
Else
newIncrement = 100
End If
Increment = newIncrement
MyBase.UpButton()
End Sub
End Class
Note: the two methods are *not* the same [value comparison, and you have to set the the corresponding base method]. I hope this works for you and you'll adapt it to your needs.
Andrej
LukeG
Ok,
try overriding UpButton() and DownButton methods, you can set wanted increment value there:
Public
Class MyNumericUpDownInherits NumericUpDown
Public Overrides Sub DownButton()
Dim newIncrement As Integer
Dim currentValue As Decimal = Value
If currentValue <= 10 Then
Public Overrides Sub UpButton()newIncrement = 1
ElseIf currentValue <= 2000 Then
newIncrement = 10
Else
newIncrement = 100
End If
Increment = newIncrement
MyBase.DownButton()
End Sub
Dim newIncrement As Integer
Dim currentValue As Decimal = Value If currentValue < 10 Then
newIncrement = 1
ElseIf currentValue < 2000 Then
newIncrement = 10
Else
newIncrement = 100
End If
Increment = newIncrement
MyBase.UpButton()
End Sub
End Class
Note: the two methods are *not* the same.
Andrej