How to format datagrid cell for money format?

  • Thread starter Thread starter [ F e r n a n d o L o p e s ]
  • Start date Start date
F

[ F e r n a n d o L o p e s ]

Hello all,
How can I do that? Format a datagrid cell to money format.
I nedd to show like this $500,00, but shows 500,0000.

Thanks in advance.

Sorry my English.

Fernando Lopes
Brazil
 
I am using similar code to represent the 'cost' field in a datagrid
bound to a dataview:

''BEGIN CODE EXAMPLE''''''''''''''''
' COST
tbc = New DataGridTextBoxColumn(m_cm.GetItemProperties()(Material.COL_COST))
With tbc
.Alignment = HorizontalAlignment.Right
.MappingName = Material.COL_COST
.HeaderText = Material.COL_COST
'.Format = "C"
.ReadOnly = False
End With
ts.GridColumnStyles.Add(tbc)
''END CODE EXAMPLE''''''''''''''''''

I'm having trouble with edits to a currency-formatted column.

With currency-formatting applied to grid column:
If I try changing a value like $4.50 to $4.51 by highlighting the '0'
and replacing it with a '1', the value reverts back to $4.50 as soon
as I leave the cell. If I swipe over the entire value, erase it then
type '4.51' it works.

With no formatting:
Any edit method works fine.

It's as if .NET doesn't recognize '$4.51' as a valid number even
though the '$' was added by it's own formatting functions.

I've also seen this behavior with 'n' formatted fields as soon as
commas are involved.

Anyone else seen this? Am I making sense?
 
Everything is wrapped up with Try, Catch. Pretty sure there's no
exceptions slipping by.

I've seen this with standard controls (TextBox, Combobox) as well but
then learned about the 'Format' and 'Parse' handlers.

Unfortunately, I can't find anything similar to apply to the datagrid.

Catching the edit and commit for a particular column just to strip and
reapply formatting sounds kind of kludgey to me.

Oh-well, Thanks!
 
I meant that the exception would be in the framework code. Unfortunate.

There are some custom DataGridColumnStyles out there. Maybe one that has
solved this issue?

I have developed a ComboBoxColumn, DateTimePicker, etc... I tried to create
a formatted TextBox that did what I mentioned, but it was behaving
strangely. Unfortunately, it also allowed the user to see the raw DB value
instead of the formatted value.

Maybe I need to try again. I'd like to implement a full range of custom
columnstyles.

Eric Cadwell
http://www.origincontrols.com
 
Back
Top