[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

DataGridView Column Header Alignment

Posted on 2006-06-14
2
Medium Priority
?
16,370 Views
Last Modified: 2012-08-13
I've found a lot of answers on how to align the Header Text for a column but when I set the HeaderText to MiddleRight alignment, there is some sort of padding after the Header text that I can't figure out how to get rid of.  Since this is hard to describe, I've posted a sample picture with the problem circled in red at: http://i7.photobucket.com/albums/y279/abso_lushen/EESample.jpg

The code I use to Right Align the column is below:
        DataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 'Aligns the Header Text
        DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 'Just aligns the cell contents

I should also mention that I've tried turning EnableHeadersVisualStyles off and that did not solve the problem.  I've also tried TopRight and BottomRight with no change.

Thanks in Advance,
Jon Beck
0
Comment
Question by:TeflonJon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
vadim63 earned 1500 total points
ID: 16931925
There's a space for the up/down arrow for sorting on that column. If you set the "SortMode" to "NotSortable", you will get what you want:

DataGridView1.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
DataGridView1.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight 'Aligns the Header Text
DataGridView1.Columns(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight 'Just aligns the cell contents
0
 

Author Comment

by:TeflonJon
ID: 16934696
Thanks for the answer.  I think the best solution for me is to use the ComponentOne FlexGrid (or similar) since I still need to allow my user to sort by column header.  With the reserved space, narrow columns still look like the column header is left aligned and I know my clients will complain about that.  I think Microsoft came out with a much better DataGridView this time but it's still not quite got the features we need for a few of our apps...  Oh well.  Thanks again.

Jon
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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