mHelpMe
mHelpMe

Reputation: 6668

WPF Datagrid Column Format Number to include commas

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

Upvotes: 18

Views: 25619

Answers (2)

Dutts
Dutts

Reputation: 6191

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>

Upvotes: 4

jimSampica
jimSampica

Reputation: 12410

You're looking for StringFormat

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

or

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

Upvotes: 40

Related Questions