I maded one post about currency formating, and the question was answered, but I am now trying to put the system formatting within a field in a datagridview, so, I C# for me is more easy to make that, and I maded, but, When I tryed to make the same in Visual Cobol, I just got errors :(
My C# code is that, remambar, is based in that code: community.microfocus.com/.../10425.aspx
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
e.Control.PreviewKeyDown -= Control_PreviewKeyDown;
e.Control.PreviewKeyDown = new PreviewKeyDownEventHandler(Control_PreviewKeyDown);
}
private void Control_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
var txtB = (TextBox)sender;
var myValue = txtB.Text.Replace(",", "").Replace("R$", "").Replace(".", "").TrimStart('0');
decimal ul;
if (Decimal.TryParse(myValue, out ul))
{
ul = ul / 100;
txtB.PreviewKeyDown -= new PreviewKeyDownEventHandler(Control_PreviewKeyDown);
txtB.Text = string.Format(System.Globalization.CultureInfo.CreateSpecificCulture("pt-BR"), "{0:C2}", ul);
txtB.PreviewKeyDown = new PreviewKeyDownEventHandler(Control_PreviewKeyDown);
txtB.Select(txtB.Text.Length, 0);
}
if (!TextIsValid(txtB.Text))
{
txtB.Text = "R$ 0,00";
txtB.Select(txtB.Text.Length, 0);
}
}
private bool TextIsValid(string myText)
{
var mn = new System.Text.RegularExpressions.Regex(@"^R\\$ ?([1-9]{1}[\\d]{0,2}(.[\\d]{3})*(,[\\d]{0,2})?|[1-9]{1}
{0,}(,[\\d]{0,2})?|0(,[\\d]{0,2})?|(,[\\d]{1,2})?)$");
if (mn.IsMatch(myText))
return true;
else
return false;
}
But, the strange thing is, in that code, in C#, the formating of text not work so fine than in the textbox, why ?