This is a migrated thread and some comments may be shown as answers.

Allow multiple decimal separators

3 Answers 205 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mickaël
Top achievements
Rank 1
Mickaël asked on 25 Jul 2011, 11:09 AM
Hello,

I'm using the RadGridView and am very pleased with it, but I'm facing a small issue I can't resolve myself :
My application is running with the French culture, which decimal separator is the comma (,).

I want my users to be able to enter decimal values with either a dot (.) or comma (,) as the decimal separator so the experience is easier for them, but I don't know how to achieve that.

What I first tried was to handle the CellValidating event of the RadGridView, manually validate the event even if a number has a dot as a decimal separator (by setting both properties e.Handled and e.IsValid to true), but I guess some upper-level internal validation occurs and my cell appears as not valid with the error message "Input was not in a correct format", which is, if I recall well, an .NET framework "Parse" exception message, which I guess you call to determine if the value is correct.

Do you know a way to allow both dot and comma as a decimal separator ?

Thanks for your interest in my question.
Regards,
Mickaël Derriey

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 26 Jul 2011, 12:17 PM
Hi Mickaël,

Let me try to explain how number work in the .NET Framework.

Numbers are internally represented in the same way in the memory no matter which culture you use. Our Bulgarian decimal separator is the same as yours, i.e. a comma. The American style uses a dot. But the important thing is that once the string is parsed regardless of the culture, the actual Decimal value that is obtained has the same byte representation in memory.

So, since the .NET Framework does not offer the functionality that you require out-of-the-box, you will have to develop your own code to handle the two different decimal separators.

One possible way to do this would be to create a custom cell editor, that will be some kind of a smart TextBox, which will accepts numbers typed with a comma and with a dot and regardless of the symbol used convert them to the desired decimal value.

Here you can learn more about creating custom cell editors. So basically, your magic textbox editor will accept string with any kind of possible decimal separator and convert them to the correct Decimal value. The implementation of such a control is beyond the scope of Telerik support.

I hope this helps.

Regards,
Ross
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Mickaël
Top achievements
Rank 1
answered on 26 Jul 2011, 01:04 PM
Hey Ross,

First, I want to thank you for your answer.
Second, after struggling with this problem another couple of hours, I found a solution which works, although it may not be the "cleanest" one. In the CellValidating event, I manually replace the dot with a comma, if any is found. This way the validation passes, and I can still perform my custom validation afterwards.

Hoping this can help someone else,
Have a great day, and thanks again for your support,
Mickaël
0
LE MEE
Top achievements
Rank 1
answered on 14 Dec 2011, 09:39 AM
Hello,

There is an other way do do this : using a numeric Converter
Numeric conversion is done using local settings.

Jean-Louis
Tags
GridView
Asked by
Mickaël
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Mickaël
Top achievements
Rank 1
LE MEE
Top achievements
Rank 1
Share this question
or