Currency Culture Formatting not applying on DataGridView Column

情到浓时终转凉″ 提交于 2019-12-06 14:21:20

you don't need a BindingSource to list all rows, just

dataGridView1.DataSource = dataTable,

and since you're using a DataTable, remove this part

dataGridView1.Columns["ColB"].DefaultCellStyle.Format = String.Format("c");

and try to use the CellFormatting event.

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 1) //Column ColB
            {
                if (e.Value != null)
                {
                    e.CellStyle.Format = "c";
                }
            }
        }

I hope it will help :)

(answer previously from the question)

Added the following line after defining the two columns, and now it works:

qBDFrmDTForDisplay.Columns["Combined Price"].DataType = Type.GetType("System.Decimal");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!