So apparently it looks better if you have the Price of a Product on the right side inside of a Column like this:
Ofcourse this is an OrderID but the look should be the same.
But at the moment mine looks more like this.
Thanks for helping; C ya!
CodePudding user response:
Setup each column for the DataGridView in the designer by clicking the chevron
Select edit columns
and select the column to set the alignment then select DefaultCellStyle and set alignment to MiddleRight.
Example using mocked data (works the same from a database table). All numeric columns have MiddleRight alignment below.
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;
}
Manually setting up alignment.
var dataGridViewCellStyle1 = new DataGridViewCellStyle { Alignment = DataGridViewContentAlignment.MiddleRight };
PriceColumn.DefaultCellStyle = dataGridViewCellStyle1;