Basically I have a datagridview which displays data from a datatable. Each cell in the datatable is a decimal with roughly 10 decimal points, how can I use the datagridview to display this data to 2 decimal points?
I have tried this (what I found in other questions):
for (int i = 0; i < this.dgvDynamics1.Columns.Count; i++)
this.dgvDynamics1.Columns[i].DefaultCellStyle.Format = "N2";
but it doesn't work
If you need any more info let me know
Thanks in advance
Try this:
this.dgvDynamics1.Columns.Items[i].DefaultCellStyle.Format = "0.00##";
this.dgvDynamics1.Columns.Items[i].ValueType = GetType(Double)
try this
private void dgvList_CellFormatting(object sender,DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 6 || e.ColumnIndex == 8)
{
e.CellStyle.Format = "N2";
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With