How do I set a column in WPF datagrid as percentage value with 2 decimal points?
Here is my declaration of the data grid in XAML:
<DataGrid
ItemsSource="{Binding}" AutoGenerateColumns="True" IsReadOnly="False" IsEnabled="True"
x:Name="dg_MyDataGrid" CanUserAddRows="False" SelectionMode="Extended" SelectionUnit="FullRow"
CanUserSortColumns="true" CanUserDeleteRows="False" AlternatingRowBackground="AliceBlue" Margin="0,252,0,23"
ColumnWidth="120">
</DataGrid>
I am dynamically binding my column in the backend C# code in one of the events as follows:
//declaration of list of custom created data type ParameterValues
List<ParameterValues> GridParameterValues;
//… some code to load the list…
//binding the list to the data grid
dg_MyDataGrid.ItemsSource = GridParameterValues;
Now my requirement is I need 4<sup>th</sup> and 7<sup>th</sup> columns to have a format such as “8.20%” instead it is showing up as 0.082
Is there any way we could automatically convert all values in a particular column which has values like 0.082 to display as “8.20 %”. I also have the requirement to display the value as “8.20 %” instead of “8.2 %”.
I really appreciate your advice!