printmedia
asked on
Column header not middle centered in vb.net
Hi all.
I have the code below and I included the code for one of the columns. What is happening is if the column header is "word wrapped" then it is no longer centered so it looks weird because the data in the row is centered but the column header is not perfectly centered but slightly to the left.
I've read that a fix is to remove the sorting, but we need the sorting for the datagrid.
Any idea how I can fix this?
I have the code below and I included the code for one of the columns. What is happening is if the column header is "word wrapped" then it is no longer centered so it looks weird because the data in the row is centered but the column header is not perfectly centered but slightly to the left.
I've read that a fix is to remove the sorting, but we need the sorting for the datagrid.
Any idea how I can fix this?
DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True 'Word wrap
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells 'Adjust the height of the rows
DataGridView1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 'Center in the middle cell contents
DataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter 'Center in the middle the column headers
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText
DataGridView1.AutoGenerateColumns = False
DataGridView1.ColumnCount = 8 'Set Columns Count
'Add Columns
DataGridView1.Columns(0).Name = "MasterItemNumber"
DataGridView1.Columns(0).HeaderText = "Master Item Number"
DataGridView1.Columns(0).DataPropertyName = "MasterItemNumber"
DataGridView1.Columns(0).Width = 120
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.