Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numericupdown force thousandsseperator to update text each keypress

When I use a numbericupdown object with thousandsseperator set to true it only updates the text to display the commas correctly when it loses focus. Is there a way to force it to refresh each time the value is changed?

like image 250
JonF Avatar asked Nov 29 '25 03:11

JonF


1 Answers

You would need to do an event. As we know, the thounsandseperator is triggered by focus we can simply call it as we type.

 private void numericUpDown1_KeyUp(object sender, KeyEventArgs e)
        {
            numericUpDown1.Focus();
            //Edit:
            numericUpDown1.Select(desiredPosition,0)
        }

So as the user type, we give the box the it focus back which is a hack to recall the thousandsseperator formatting.

Note: Problems with hacks are wierd situations which calls for more hacks... e.g: Cursor sets back to the front of the text... you would need another hack to fix it.

Experiment with the other events to find the one that fits your case.

Edit: Btw, if you do want to go even further with this ...

  1. Keep Track of the cursor.
  2. Put back the cursor at the right position when keyup is called. Setting the cursor position in numericUpDown control
like image 58
Reza M. Avatar answered Nov 30 '25 16:11

Reza M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!