I'm using the following code following code for textboxes to get item price
//textBox 1 thru 16 allows enduser to enter price of the item.
private void textBox2_TextChanged(object sender, TextChangedEventArgs e)
{
Double value2;
if (Double.TryParse(textBox2.Text, out value2))
try
{
textBox2.Text = value2.ToString();
}
catch
{
MessageBox.Show("Please enter a valid decimal into the textbox!")
}
}
When I run the debugger, you can enter numbers but if you try to enter the decimal it places the cursor in front of the numbers entered instead of where you enter it. Example I want 99.99, when I enter it it will put.9999. What can I do to get it to place it while typing in the textBox instead of trying to arrow back to add correctly.
Another example I have and it is doing the same thing as above is:
private void textBox20_TextChanged(object sender, TextChangedEventArgs e)
{
Double value20;
var numberStyle = NumberStyles.AllowLeadingWhite |
NumberStyles.AllowTrailingWhite |
NumberStyles.AllowLeadingSign |
NumberStyles.AllowDecimalPoint |
NumberStyles.AllowThousands |
NumberStyles.AllowExponent;
if (double.TryParse(textBox20.Text, numberStyle, CultureInfo.InvariantCulture, out value20))
textBox20.Text = value20.ToString();
else
MessageBox.Show("Please enter the percent value via decimal structure.");
}