There seems to be no way to set the DataFormatString property. I finished binding the data source to the table, and then looked at all the cells and formatted them manually:
DataGridView.AutoGenerateColumns = true;
DataGridView.DataSource = dbconnection.getDataReader();
DataGridView.DataBind();
int result;
for (int i = 0; i < DataGridView.Rows.Count; i++)
{
foreach (TableCell c in DataGridView.Rows[i].Cells)
{
if (int.TryParse(c.Text, out result))
{
c.Text = String.Format("{0:n0}", result);
}
}
}
This method works great for me. Not sure how this will expand with a large dataset, although I assume that everything will be fine.
source
share