Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NumericUpDown Control and Thousands Separtor 1

Status
Not open for further replies.

Bchemist

Programmer
Apr 3, 2002
91
0
0
US
I have a numericupdown control on a form. It has the thousands separtor set to true (Since some value can be in millions, it is MUCH easy to view) On the lower values the control works fine obivously in the values that a user would use the up/down arrows to move to (say 20) the comma doesn't matter, however at the higher values (say 1,000,000) the user generally types the values in.

Therein lies the problem. When I user types the values in the up/down control doesn't format the value with commas until they click an arrow.

Is there a way to trigger the comma formating from code?
 
This is a simple trick:
Code:
  Private Sub NumericUpDown1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles NumericUpDown1.KeyPress

         If e.KeyChar >= "0"c AndAlso e.KeyChar <= "9"c Then

            Dim str As String = NumericUpDown1.Text
            NumericUpDown1.Text = str + e.KeyChar
            e.Handled = True

        End If
This is not perfect. Try to select some text or to put the cursor in the middle of the text and see what happens. Try ro inherit from this control. Maybe there are protected members that can help you.
 
Thanks for the help. That worked great, and in combination with a little bit of text selection code, I find very little problems with it.

Have a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top