我有一个绑定到DataTable的DataGridView。 我将默认单元格样式设置为数字,但它不会将列对齐。 这是预期的行为吗?
private void shipmentDetailsDataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
shipmentDetailsDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
shipmentDetailsDataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
shipmentDetailsDataGridView.AllowUserToResizeColumns = true;
shipmentDetailsDataGridView.Columns[Glossary.Total].DefaultCellStyle.Format = "N2";
shipmentDetailsDataGridView.Columns[Glossary.TotalInvoice].DefaultCellStyle.Format = "N2";
shipmentDetailsDataGridView.Columns[Glossary.UnitPrice].DefaultCellStyle.Format = "N2";
shipmentDetailsDataGridView.Columns[Glossary.Quantity].DefaultCellStyle.Format = "N0";
}
答案 0 :(得分:0)
是的,这是预期的行为。来自MSDN documentation - 强调我的:
Format属性指定如何将单元格值格式化为字符串。
要右对齐列,请尝试以下操作:
shipmentDetailsDataGridView.Columns[Glossary.Quantity].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;