Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Datagrid Column Format Number to include commas

Tags:

c#

wpf

datagrid

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

like image 737
mHelpMe Avatar asked Sep 03 '13 15:09

mHelpMe


2 Answers

You're looking for StringFormat

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

or

<DataGridTextColumn Binding="{Binding myInt, StringFormat={}{0:N0}}"/>
like image 119
James Sampica Avatar answered Nov 18 '22 04:11

James Sampica


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>
like image 4
Dutts Avatar answered Nov 18 '22 04:11

Dutts