Click here to Skip to main content
15,903,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts,

a DataGridView is used to display some measured values. Among those values are currents. They are stored in Ampères within the application.

Since those values are relatively small, I would like to tell DataGridView to display Milliampères instead.

There is a possibility to display large magnitudes[^]. And there is one for per mille[^] values. But the first is the wrong way round, the latter inserts an additional per-mille-symbol.

What format specifier multiplies a value by 1000 before displaying it?


Edit: The grid is data-bound. So there is no code that sets an individual cell's value. Therefore I'm looking for a format specifier that can be used as DataGridViewCellStyle.Format.
Posted
Updated 28-Oct-11 3:01am
v2

Why can'y you do this (value*1000).ToString("0.00") ?
 
Share this answer
 
Comments
lukeer 28-Oct-11 9:01am    
Forgot to mention that in the original post. I'm looking for something to use in DataGridViewCellStyle.Format. I updated the question.
Just delete the & ChrW(&h2030) part because that is the per-mille-symbol. You could also replace it with a symbol you like. You can use charmap (start -> run... -> type: charmap) to to lookup a wide-char that is suitable or just simply add " amp" to the format string.

Good luck!
 
Share this answer
 
Comments
lukeer 28-Oct-11 9:03am    
Forgot to mention that in the original post. I'm looking for something to use in DataGridViewCellStyle.Format. I updated the question.
E.F. Nijboer 28-Oct-11 9:54am    
Have a look at "To format data in cells" at the bottom of the page:
http://msdn.microsoft.com/en-us/library/95y5fz2x.aspx?appId=Dev10IDEF1&l=EN-US&k=k%28VS.CELLSTYLEDIALOG%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK&k=VERSION=V4.0%22%29&rd=true

...and check out custom formatting (you can also download a utility to help you on this page):
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

Formatting only defines how to format the value, meaning it isn't for calculations and such. So, you might need to use a DataGridViewCellFormattingEventHandler after all:
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/95e7e7ef-2e71-412f-abe5-ffbee2c12c18/
I do this by having a view-model class that sits between the application data and the grid. The grid is bound to a list of these binding helpers, instead of to the list of business objects directly. The binding helper can then perform whatever two way translation is needed to get the data into the form that the users want to see it (i.e. unit conversions, not just X->mX but m->ft and other similar things).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900