0

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 ','.

user3144640
  • 103
  • 1
  • 13
  • 1
    You don't set everything to invariant culture, you set an invariant culture and then use it where relevant. Somewhere you are going to or from string and assuming culture, when you should have set an invariant in the app and used it when doing that. If you have FxCop, you can enable globalization rules and it will track all the problematic code for you. Parse, TryParse, Convert, ToString and String.Format are the usual suspects. – Tony Hopkinson Jan 31 '14 at 12:30
  • As I said I need also to use in dataGridView to display '.' instead of ',' – user3144640 Jan 31 '14 at 12:43
  • Not about what you need, its, about what the user needs, and they need to enter and see data in their culture, not your's because you are struggling to write the software properly. – Tony Hopkinson Jan 31 '14 at 21:32
  • That may have been a bit harsh. Thing about globablisation and localisation in .net, is once you start using it consistently it just works. If you try and bend it or take short cuts, you just end up in a mess. – Tony Hopkinson Jan 31 '14 at 21:35

2 Answers2

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")
Community
  • 1
  • 1
Junaith
  • 3,298
  • 24
  • 34
  • For this certain application I only need this invariant culture it will be used in my country only and if I don't do this the whole application is useless – user3144640 Jan 31 '14 at 12:19
  • @user3144640 - add a entry in user doc or release notes ask users to switch your country's culture. Its up to you.. the link given in the answer might be helpful. – Junaith Jan 31 '14 at 12:54
  • at least tell me how to Make dataGridView use '.' instead of ',' to recognize to change culture or whatever this could answer my question I have 2 columns displaying decimals so foreach(DataGridViewRow row in dataGridView1.Rows){ } – user3144640 Jan 31 '14 at 13:02
  • Thank you, and put this in the Load Event ? – user3144640 Jan 31 '14 at 13:29
  • @user3144640 - If you have defined the columns through code add it in the `InitializeComponent` method or if you have bound the grid to the database do it in `DataBindingComplete` event handler. If it works accept the answer and upvote it ;) – Junaith Jan 31 '14 at 13:30
0

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.

Sinatr
  • 20,892
  • 15
  • 90
  • 319
  • For this certain application I only need this invariant culture it will be used in my country only and if I don't do this the whole application is useless – user3144640 Jan 31 '14 at 12:19
  • You said yourself *on certain computers*. Your application is running on PCs with different language settings. Make them similar = problem solve, -OR- make a proper application, where I (as user) can use my numeric keyboard to enter decimal point. – Sinatr Jan 31 '14 at 12:28
  • How to make them similar I don't have access to user application and I want to Force this I don't want to give option – user3144640 Jan 31 '14 at 12:44