Just replace:
DataGridView1.Columns(3).DefaultCellStyle.Format = "#.###"
by:
DataGridView1.Columns(3).DefaultCellStyle.Format = "N3"
where "N3"
means numeric data with three decimals. If all columns are to be "N3"
, you can do it at once with:
DataGridView1.DefaultCellStyle.Format = "N3"
you can also apply a general cell alignment, to all cells in the data grid, for instance:
DataGridView1.DefaulCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
Finally, you can also define general (all columns) numeric format at DataGridView properties window, with Format option under DataGridViewCellStyle box.
And as you can see, there is no need for loops here while the style definitions are not specific.