c# - Exclude certain values from a numeric up down -


i using c# vs2013 in .net 4.5.2.

basically, have numeric updown user can select values from. however, selectable values 1, 2, 3, 4, 6, 12, , multiples of 24. there can that, or simpler have combobox?

you can create custom numericupdown this

class customnumericupdown : numericupdown {     private int currentindex = 0;     private decimal[] possiblevalues = null;     public decimal[] possiblevalues     {                 {             if (possiblevalues == null)             {                 possiblevalues = getpossiblevalues().toarray();             }             return possiblevalues;         }     }      public override void upbutton()     {         if (base.useredit)         {             this.parseedittext();         }         var values = possiblevalues;         this.currentindex = math.min(this.currentindex + 1, values.length - 1);         this.value = values[this.currentindex];     }      public override void downbutton()     {         if (base.useredit)         {             this.parseedittext();         }         var values = possiblevalues;         this.currentindex = math.max(this.currentindex - 1, 0);         this.value = values[this.currentindex];     }      private ienumerable<decimal> getpossiblevalues()     {         foreach (var value in new decimal[] { 1, 2, 3, 4, 6, 12 })         {             yield return value;         }         (decimal = 24; < maximum; += 24)         {             yield return i;         }     } } 

note: screws acceleration feature. , needs more effort respond maximum property changed during runtime.

also worth noting if maximum value large, create huge array. small values fine. rid of array need own state machine implementation.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -