CF 2.0: Problem with DataGrid and decimal column

C

Carmine Moleti

Hi to everyone,

This is the very first application I'm writing in C# .Net 2.0 for a
Smart device.

I've a class which, among its properties, there's one whose type is decimal.
This class' instances are bound to a datagrid via BindingSource.
When debugging via the emulator the datagrid correctly reports the value
in the decimal property.

Deploying the application to the pocket pc (WM 5.0) everything works ok
except for the decimal column.

E.g.:

If the property has a value of 0.52, the emulator displays 0.52 (as I
expected), while on the pocketpc it displays 52!
Summing up the column values for each row in the datagrid actually
produces the sum of only the fractionary parts!

I've read over the internet that with CF 1.1 there was a problem with
decimal columns, is it true? Does this still holds true for CF 2.0?

Thanks in advance for your help.

Regards,
Carmine
 
I

Ilya Tumanov [MS]

No, there are no problems like this with decimal columns. In fact, DataGrid
does not care if it's decimal or not, it simply does .ToString() to show
data, so you can try that and see which string you'll get.

--
Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
C

Carmine Moleti

Ilya Tumanov [MS] ha scritto:
No, there are no problems like this with decimal columns. In fact, DataGrid
does not care if it's decimal or not, it simply does .ToString() to show
data, so you can try that and see which string you'll get.

Ilya, you're right. I've followed your advice of dumping the property's
contents via .ToString(), and actually got the "unexpected" result.

What could it be that makes this "conversion" happens? (It works in the
emulator)

Thanks for pointing me in the right direction.
 
C

Carmine Moleti

Carmine Moleti ha scritto:
Ilya Tumanov [MS] ha scritto:
No, there are no problems like this with decimal columns. In fact,
DataGrid does not care if it's decimal or not, it simply does
.ToString() to show data, so you can try that and see which string
you'll get.

Ilya, you're right. I've followed your advice of dumping the property's
contents via .ToString(), and actually got the "unexpected" result.

What could it be that makes this "conversion" happens? (It works in the
emulator)

Forgot to mention I've also used the "Format" property of the
DataGridTextBoxColumn.
Setting it to "c" on the emulator still produced the correct behaviour,
while on the device 0.52 is represented by "$ 52.00" !
 
B

biondo

How are you loading this number...

I had similar problem when inserting numbers from ".txt" file to SQLCE...
The problem was in the regional settings - decimal symbol...

maurizo


Carmine Moleti said:
Ilya Tumanov [MS] ha scritto:
No, there are no problems like this with decimal columns. In fact,
DataGrid does not care if it's decimal or not, it simply does .ToString()
to show data, so you can try that and see which string you'll get.

Ilya, you're right. I've followed your advice of dumping the property's
contents via .ToString(), and actually got the "unexpected" result.

What could it be that makes this "conversion" happens? (It works in the
emulator)

Thanks for pointing me in the right direction.
 
C

Carmine Moleti

Hi Maurizio,
How are you loading this number...

I had similar problem when inserting numbers from ".txt" file to SQLCE...
The problem was in the regional settings - decimal symbol...

The datagrid is bound to a collection implemented via BindingList<Prodotto>.

When I add items to the collection, the datagrid gets populated
automatically.

I have specified "N2" as format for the datagridtextboxcolumn, and on
the device I see that "0.52" becomes "52.00"!
This _doesn't_ happen in the emulator.

Also tried to set a new CultureInfo for the colum without luck.

Thanks for your help
 
B

biondo

I'm working still on VS2003 (because of CE 4.2) so I don't have the
datagridtextboxcolumn.Format property..

Try to see your data before binding to the grid to find out if it's the grid
property that changes "0.52" to "52.00" (format problem),
or this change happened before...

maurizio
 
C

Carmine Moleti

Try to see your data before binding to the grid to find out if it's the grid
property that changes "0.52" to "52.00" (format problem),
or this change happened before...

Step by step debug showed that the property is correctly held, both with
databinding and with unbound objects.

Totally clueless.
 
B

biondo

In one of your post... you have written
have specified "N2" as format for the datagridtextboxcolumn...

change N2 with "0.00"...

Or post part of your code where you define the datagridcolumns

maurizio
 
C

Carmine Moleti

have specified "N2" as format for the datagridtextboxcolumn...
change N2 with "0.00"...

Ok, I'll try as soon as I'll get home. I'll let you know.
Or post part of your code where you define the datagridcolumns
It's automatically generated by IDE!
 
C

Carmine Moleti

Carmine Moleti ha scritto:
No luck :(
It keeps showing data the wrong way.

Further and deeper investigation with debug on the device showed that,
most likely, it has nothing to do with format.

Decimal data is "automatically" converted the wrong way upon creation of
the objects of the collection.

So, the "drama" has finally come to an end :)

The culprit do have something to do with CulturInfo.
In the XML I have encoded decimal values as "0.52", I tried to encode
them as "0,52" and everything works properly.

Thanks a lot for your precious help, and for your patience.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top