Hi,
On the numeric keypad there is a button (Del or . ).
Pressing this button in MS_Excel it gives back a , instead of a . in numeric fields.
Is it possible to get this behaviour for the whole application without writing code in every form?
Thanks for your help.
With regards,
Frits van Ooijen
Decimal point is comma on numeric keypad
Answers approved by DevExpress Support
Hi Frits,
This problem doesn't directly relate to our components. It is widely discussed on the Internet. For example, please see the following link:
dot vs comma
As a possible solution, I suggest that you use the editor's numeric mask, and set the NumberFormatInfo.NumberDecimalSeparator property to a necessary character.
See the attached sample.
Thanks
Dimitros
Hello Frits,
You are right, most likely, you'll have to customize some controls in your application individually, to apply this solution. However, please note that it is enough to set the culture settings, such as NumberDecimalSeparator, only once, when the application is started, as shown in the following code:
C#CultureInfo culture = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name, true);
culture.NumberFormat.NumberDecimalSeparator = ",";
System.Threading.Thread.CurrentThread.CurrentCulture = culture;
Please let me know if you need any further help.
Thanks,
Anatol
Hi Anatol,
I found a workaround that works for me.
In the attached sample I did the following:
Create a form called <Basis> which inherits from
public partial class Basis : DevExpress.XtraEditors.XtraForm
In design of the form basis set the option KeyPreview to true
Make a event on KeyDown
private void Basis_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData == Keys.Decimal)
{
e.SuppressKeyPress = true;
SendKeys.Send(",");
}
}
The MDI-Children inherits
public partial class Form1 : Basis
Now the decimal key on the numeric keyboard gives always a , instead of a . character.
It works on a textbox and on a gridview.
Is there any reason why I shouldn’t implement this in my application.
With regards,
Frits van Ooijen
Hello Frits,
I've tested your solution, and found only one situation when it doesn't work: with this design, our MaskManager cannot correctly handle the decimal separator pressing, and you are able to make two decimal separators within a single field. As a result, the validation error will occur when you try to leave the field. I don't know whether it is a serious problem for you.
I should also add that with my culture settings (en-us), it is still required to change the NumberDecimalSeparator property, to make this solution work.
Thanks,
Anatol