C# 无法在DataGridview C中查看单元格的十进制值#
我无法在gridview上显示“价格”单元格的值,以下是我的代码:C# 无法在DataGridview C中查看单元格的十进制值#,c#,datagridview,C#,Datagridview,我无法在gridview上显示“价格”单元格的值,以下是我的代码: DataColumn idCol2 = new DataColumn(); idCol2.DataType = System.Type.GetType("System.Int32"); idCol2.ColumnName = "Id"; table.Columns.Add(idCol2); DataColumn SKUCol2 = new DataColumn()
DataColumn idCol2 = new DataColumn();
idCol2.DataType = System.Type.GetType("System.Int32");
idCol2.ColumnName = "Id";
table.Columns.Add(idCol2);
DataColumn SKUCol2 = new DataColumn();
SKUCol2.DataType = System.Type.GetType("System.String");
SKUCol2.ColumnName = "SKU";
table.Columns.Add(SKUCol2);
DataColumn ProdNameCol2 = new DataColumn();
ProdNameCol2.DataType = System.Type.GetType("System.String");
ProdNameCol2.ColumnName = "Product Name";
table.Columns.Add(ProdNameCol2);
DataColumn DescCol2 = new DataColumn();
DescCol2.DataType = System.Type.GetType("System.String");
DescCol2.ColumnName = "Product Description";
table.Columns.Add(DescCol2);
DataColumn PriceCol2 = new DataColumn();
PriceCol2.DataType = System.Type.GetType("System.Decimal");
PriceCol2.ColumnName = "Price";
table.Columns.Add(PriceCol2);
DataColumn[] keys2 = new DataColumn[5];
keys2[0] = idCol2;
table.PrimaryKey = keys2;
LivePOS livepos = new LivePOS(clientId, clientSecret);
_products = livepos.GetProducts(apiKey, token);
foreach (var p in _products)
{
table.Rows.Add(p.Id, p.Sku, p.Name, p.Description , p.SellingPrice);
}
table.DefaultView.Sort = "Id ASC";
dataGridView1.DataSource = table;
this.dataGridView1.DefaultCellStyle.Format = "N4";
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells[0].ReadOnly = false; //id
row.Cells[1].ReadOnly = true; //sku
row.Cells[2].ReadOnly = true; //name
row.Cells[3].ReadOnly = true; //description
}
请帮助我:)这个代码有什么错误吗?我在Form_Load事件中创建了名为“table”的datatable的新实例。除此“价格”列外,所有单元格值均正确显示。您的价格列的数据类型应为双精度而非十进制。请查看此链接
希望对您有所帮助您使用的是哪种类型的产品,以DB为单位进行定价,并提供来自_products…
DECIMAL(19,4)的样本值将需要9个存储字节货币将需要8个存储字节
请验证并澄清数据库中定义的价格数据类型。您能否举例说明显示器的问题,如预期的数字和显示的数字?我想您的顺序正好相反。。最好将Currency的数据类型设置为DecimalPrice是Products类上的DecimalPrice,但当我尝试使用list\u Products绑定gridview时,它会显示价格