Solved

DataGridView Column Header Alignment

Posted on 2006-06-14
2
16,177 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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