MaskedTextBox - Different behavior on different machines, Why?
Hi
I'm having a weird bug in my application. This is my first time in this forum I hope you can help me because this bug is makÃ*ng me crazy.
It's a desktop application where I have a form with some MaskedTextBox in it. The goal of these text boxes is allow the user to introduce values with format "000.000".
When the user modifies the textbox, the value is stored in a internal variable and until then everything works fine. The problem appear when the application reloads the textbox control from the variable. In my computer the value is retrieved correctly, the application shows in the text box the same value the user has introduced before, but in some computers the value is retrieved wrong. For instance, the user inserts 001.000 and when the application reloads the control, the value updates to 100.000.
First time I thought that it would be a Culture issue, but the user uses the same as mine (es-ES) and I have included information about culture in the code (invariant culture). This is the definition of the textbox:
Code:
this.tbxFrequency10.Culture = new System.Globalization.CultureInfo("");
this.tbxFrequency10.Location = new System.Drawing.Point(177, 254);
this.tbxFrequency10.Mask = "000.000";
this.tbxFrequency10.Name = "tbxFrequency10";
this.tbxFrequency10.PromptChar = '0';
this.tbxFrequency10.Size = new System.Drawing.Size(135, 20);
this.tbxFrequency10.TabIndex = 116;
this.tbxFrequency10.TextMaskFormat = System.Windows.Forms.MaskFormat.IncludePromptAndLiterals;
this.tbxFrequency10.Validated += new System.EventHandler(this.Control_Validated);
The main problem here is I can't reproduce the bug the user has. Just in case I changed my Windows regional configuration in order to try to reproduce the bug but with no success. Anyone has an idea about what could be the reason of this bug?
Thanks in advance. Sorry for my english.
Regards,
Re: MaskedTextBox - Different behavior on different machines, Why?
Did you try?
this.tbxFrequency10.Culture = new System.Globalization.CultureInfo("es-ES");
If not then you can try by
Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ES", false);
Re: MaskedTextBox - Different behavior on different machines, Why?
Thanks for your reply MAHEY. Yes, I tried both and the behavior was the same.
As long as I can see, the maskedtextbox culture only affects the character shown as a decimal separator. With es-Es the separator is ',' instead of '.' with InvariantCulture.
The problem arise from validation of the control, where I have this piece of code:
Code:
if (control.DataBindings.Count > 0)
control.DataBindings[0].ReadValue();
Before that, the value showed in the textbox is the value the user put on the box, for example "001.000", after the binding, the value shown changes to "100.000" despite of that the value of the internal variable bound with the control still have the same value "001.000". The showed value always change in the same way, the value is recalculated as if the first 0's doesn't exist ("000.100" --> "100.000", "001.010" --> "101.000"...)