I have a textbox that gets a decimal value say 10500.00
the problem is that the way I have it, when you enter a value and then enter the decimals it would not allow you to backspace or clear the textbox to input a new value.. it just gets stuck.. I have tried to set the value back to 0.00 but i think i placed it on the wrong place because it wont change it. Here is my code
private void txtTransferAmount_KeyPress(object sender, KeyPressEventArgs e)
{
bool matchString = Regex.IsMatch(textBoxTransfer.Text.ToString(), @".dd");
if (matchString)
{
e.Handled = true;
}
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
{
e.Handled = true;
}
// only allow one decimal point
if (e.KeyChar == '.' && (sender as TextBox).Text.IndexOf('.') > -1)
{
e.Handled = true;
}
}
What type of change do you suggest so that I may be able to backspace or clear the texbox an enter a new value?.
See Question&Answers more detail:os