问题
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