Solved

DataGridView Column Header Alignment

Posted on 2006-06-14
2
15,852 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
2 Comments
 
LVL 10

Accepted Solution

by:
vadim63 earned 500 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now