Set Culture Invariant for whole application(thread) Point '.' instead of ','

二次信任 提交于 2019-12-25 02:39:31

问题


I have this application which requires the user to introduce some prices etc. working with dataGridViews also to display. The problem is that on certain computers the '.' this is treated as ',' I managed to get some TextBox leave event to and set the Invariant Culture for it but is useless as im using dataGridViews to display and also ReportViewer I also have a code that converts numbers to text and with this problem my application is worthless in current state with this Culture problem so I need to set everything to Invariant Culture no matter what it will take the value for example :

2.00 as 200,00 on that computer I want to use invariant culture no matter what just display 2.00 working with '.' instead of ','.


回答1:


I would not recommend to force an application to culture invariant or to a particular culture. But thats what you want... check the answer of this SO question.

If you want to change only the datagridview then change the DefaultCellStyle.FormatProvider to use the culture of your country. In the example below I have change the FormatProvider to use English-US culture.

Column.DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("en-US")



回答2:


You can try following, before anything else:

CultureInfo.CurrentUICulture.NumberFormat.NumberDecimalSeparator = ".";

However, I'd recommend to distinguish user interaction and let it to happens in default culture.



来源:https://stackoverflow.com/questions/21479745/set-culture-invariant-for-whole-applicationthread-point-instead-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!