Silverlight / WPF - silverlight data grid with both autogenerate columns true and values with two decimal plac

Asked By Ramachandran on 23-Jun-12 09:35 AM
how to populate the silverlight data grid with auto generate columns true and values with two decimal places......

my code is here.....


  <sdk:DataGrid Grid.Row="3"  ItemsSource="{Binding ApplyDataList,Mode=TwoWay}" Background="Yellow" Foreground="blue" Height="100"  Margin="0,0,0,0" Width="900" AutoGenerateColumns="True">
      </sdk:DataGrid>


i tried with applying  stringformat {0:n2} and stringformat {###:##} but not worked for that.....
D Company replied to Ramachandran on 23-Jun-12 10:15 AM
Hello,

I think u can try this way , it works for me

<silverLControl:DataGridTextColumn Binding="{Binding Price,StringFormat='#.##'}" Header="SalesPrice"></
silverLControl:DataGridTextColumn>


Thanks
D
kalpana aparnathi replied to Ramachandran on 24-Jun-12 07:21 AM
hi,

Try with this dynamically:

public static DataGridTextColumn CreateFloatColumn(int index, string fieldName, string header, string description)
    {
      DataGridTextColumn column = new DataGridTextColumn();
      column.Header = header;
      column.HeaderStyle = BuildColumnHeaderStyle(description);
      column.Binding = new Binding("floatValuesList[" + index + "]");
      column.Binding.StringFormat = "0.00";
      column.CellStyle = BuildFloatCellStyle(fieldName, description);
      return column;
    }

Regards,