顯然,如果您在像這樣的列的右側有產品的價格,它看起來會更好:
當然,這是一個 OrderID,但外觀應該是一樣的。

但目前我的看起來更像這樣。

感謝您的幫助;喲!
uj5u.com熱心網友回復:
通過單擊 V 形圖示在設計器中為 DataGridView 設定每一列

選擇edit columns并選擇要設定對齊方式的列,然后選擇 DefaultCellStyle 并將對齊方式設定為 MiddleRight。
使用模擬資料的示例(與資料庫表的作業方式相同)。所有數字列在下方都有 MiddleRight 對齊方式。
private void OnShown(object sender, EventArgs e)
{
dataGridView1.AutoGenerateColumns = false;
DataTable table = new DataTable();
table.Columns.Add("Item", typeof(string));
table.Columns.Add("Qty", typeof(int));
table.Columns.Add("Price", typeof(decimal));
table.Columns.Add("Total", typeof(decimal));
table.Columns["Total"].Expression = "Qty * Price";
table.Rows.Add("First item", 2, 60);
table.Rows.Add("Second item", 2, 50);
table.Rows.Add("Third item", 1, 20);
dataGridView1.DataSource = table;
}

手動設定對齊。
var dataGridViewCellStyle1 = new DataGridViewCellStyle { Alignment = DataGridViewContentAlignment.MiddleRight };
PriceColumn.DefaultCellStyle = dataGridViewCellStyle1;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/394762.html
上一篇:如何繪制自定義滑塊控制元件?
