The documentation for DataTable.Locale
doesn't say anything about setting number formats; it says:
Gets or sets the locale information used to compare strings within the table.
So it may not do what you're expecting it to do.
If you're auto-generating columns you may need to store the values as strings in the DataTable
instead so you can specify the formatting. Another option is to attach to the AutoGeneratingColumn
event to set custom column properties:
excerpt from MSDN :
private void dataGrid1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
// Modify the header of the Name column.
if (e.Column.Header.ToString() == "Name")
e.Column.Header = "Task";
// Replace the DueDate column with a custom template column.
if (e.PropertyName == "DueDate")
{
// Create a new template column.
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Due Date";
templateColumn.CellTemplate = (DataTemplate)Resources["dueDateCellTemplate"];
templateColumn.CellEditingTemplate = (DataTemplate)Resources["dueDateCellEditingTemplate"];
templateColumn.SortMemberPath = "DueDate";
// ...
// Replace the auto-generated column with the templateColumn.
e.Column = templateColumn;
}
// Cancel AutoGeneration of all boolean columns.
if (e.PropertyType == typeof(bool))
e.Cancel = true;
if (e.PropertyName == "ValueField")
{
(e.Column as DataGridTextColumn).Binding.StringFormat = "N5";
}
}
I will say that auto-generating columns is a nice way to quickly prototype a grid but I usually end up directly configuring the columns to specify number formats, etc.