Please see the screenshot below for a MaskedTextBox:
and the code below:
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e)
{
maskedTextBox1.ValidatingType = typeof(System.Decimal);
maskedTextBox1.TypeValidationCompleted += new TypeValidationEventHandler(maskedTextBox1_TypeValidationCompleted);
}
void maskedTextBox1_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
{
if (!e.IsValidInput)
{
MessageBox.Show("Validation failed");
}
else
{
Decimal value = (Decimal)e.ReturnValue;
MessageBox.Show("Validation suceeded");
}
}
}
e.IsValidInput is always false if I enter a value less than 1000. If I enter a value above 1,000 then it works i.e. the cast to a decimal works. I believe this is because the comma is missing with values less than 1,000. How do I make the comma optional?