16
votes

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

2

2 Answers

38
votes

You're looking for StringFormat

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

or

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

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>