[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DataGridView Header text not centered

Posted on 2009-04-07
5
Medium Priority
?
975 Views
Last Modified: 2012-05-06
I've a DataGridView where the header texts aren't correctly centered, as you can see by the picture. I've the following code for my DataGridView. Why does this happens?

Thanks for your help.

jppinto
Me.grdMissingParts.RowHeadersWidth = 25
Me.grdMissingParts.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.grdMissingParts.Columns("Part Number").Width = 150
Me.grdMissingParts.Columns("Part Number").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.grdMissingParts.Columns("Descrição").Width = 250
Me.grdMissingParts.Columns("Descrição").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.grdMissingParts.Columns("URQ").Width = 60
Me.grdMissingParts.Columns("URQ").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.grdMissingParts.Columns("Paragem").Width = 60
Me.grdMissingParts.Columns("Paragem").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter

Open in new window

DataGridView.JPG
0
Comment
Question by:jppinto
  • 3
  • 2
5 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24091870
Hi jppinto,
Do you mean the column "URQ" ? Don't you have spaces in the column name ?
0
 
LVL 33

Author Comment

by:jppinto
ID: 24091917
No, I don't have spaces in the column name. The problem is with the first 3 columns name as you can see by the picture, they are not well centered.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24092043
Strange ... Try this snippet after your code
        For Each col As DataGridViewColumn In Me.DataGridView1.Columns
            col.HeaderText = col.HeaderText.ToString.Trim
        Next

Open in new window

0
 
LVL 33

Author Comment

by:jppinto
ID: 24102590
I've tryed your code but with no sucess...the problem still exists!

jppinto
0
 
LVL 33

Accepted Solution

by:
jppinto earned 0 total points
ID: 24102753
Solved!

The column header cells reserves space for the sort glyph when calculating center justification. I had to disable sorting on the columns so that the alignment looks centered. Like this:

Me.grdMissingParts.Columns("Part Number").SortMode = DataGridViewColumnSortMode.NotSortable

jppinto
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question