17

I thought this would be rather simple and probably is but I cannot find anything on google. I have a WPF application with a datagrid bound to my object which contains properties of type bool, string & int. Where int is displayed I want to show 30,000 rather than 30000. How is this acheieve?

Any help would be great, Thanks, M

mHelpMe
  • 6,336
  • 24
  • 75
  • 150

2 Answers2

40

You're looking for StringFormat

<DataGridTextColumn Binding="{Binding myInt, StringFormat=\{0:N0\}}"/>

or

<DataGridTextColumn Binding="{Binding myInt, StringFormat={}{0:N0}}"/>
jamesSampica
  • 12,230
  • 3
  • 63
  • 85
4

If you use a DataGridTextColumn you can use a StringFormatter on your binding

<DataGrid>
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding MyNumber, StringFormat={0:#,0} {1:#,0}}" />
    </DataGrid.Columns>
</DataGrid>
Dutts
  • 5,781
  • 3
  • 39
  • 61
  • I accidentally gave you an undeserved +1 there... this solution does not build. The single apostrophes break the XAML! – Riegardt Steyn May 30 '14 at 10:40
  • 1
    @Heliac apostrophe marks are not required. `Binding="{Binding number, StringFormat={}{0:n2}}"` will show two decimal places e.g. – oleksa Dec 23 '15 at 13:32
  • 2
    Apologies, I wrote that out on my phone and couldn't recall the syntax... I've updated the answer. – Dutts Dec 24 '15 at 14:42