Search code examples
c#numericupdown

Set fixed Values in a NumericUpDown control


In contrast to setting the minimum and maximum value for a NumericUpDown how do I get the user to select only between different Preset Values? (e.g. 5, 8, 10, 15, 20, 25).

EDIT: Can I differentiate between the ValueChanged Event by 1) clicking on the arrows of numericUpDown and by 2) changing the Value manually with the keybaord?


Solution

  • As the control itself does not support this, you will have to handle it manually. Attach a method to the ValueChanged event and check if the value is one of those. If not, then adjust appropriately.

    If the allowed values are at least two values apart, you can easily check if it is going up or down and don't need to store the previous value to determine that.