Hi Kira,
First of all, thanks a lot for the answer! It worked like charm :)
Regarding the code I'm using to format the value as numeric, here is the piece of code I'm using for the TextChanged event of the TextBox control:
private void textBox_TextChanged(object sender, EventArgs e)
{
TextBox textBox = (TextBox)sender;
try {
int pos = textBox.SelectionStart;
int lengthBefore = textBox.Text.Length;
int n = int.Parse(_remove_comma(textBox.Text));
if (n == 0)
return;
textBox.Text = n.ToString("N0");
int lengthAfter = textBox.Text.Length;
textBox.SelectionStart = lengthBefore == lengthAfter ? pos : (pos + 1);
}
catch (Exception ex) {
//textBox.Text = "";
}
}
The _remove_comma method does exactly what it says :)
private static string _remove_comma(string s)
{
return Regex.Replace(s, ",", "", RegexOptions.Compiled);
}
The code above works, but it's not perfect... I know it has some problems related to the position of the caret (depending if a new , was introduced while formatting the number) so I will try to fix it and once it's working properly I will re-post it here.
Once again, thank you for the help!
Best regards,
Andrei