locked
Datagridview headerText alignment padding on the right or center RRS feed

  • Question

  •  

    Hi,

    When I set the HeaderText to MiddleCenter  or  MiddleRight alignment, there is some sort of padding after the Header text that I can't figure out how to get rid of.

    Is that space reserved for sorting (triangular)  icon (just to make sure)? Otherwise why I can't just perfectly center or right align my header text? 

    I did center alignment as following:

    dgvMain.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;

    Thanks in advance.


     

    • Edited by ShukraRai Wednesday, May 5, 2010 3:54 AM
    Wednesday, April 28, 2010 12:11 AM

Answers

All replies

  • the remaining space in right of datagridview column's header is reserved for sorting(triangular) icon..

     

    jayant

    Wednesday, April 28, 2010 7:07 AM
  • Hi,

    Try this.

    dataGridView1.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
    dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
    

    • Marked as answer by Harry Zhu Tuesday, May 4, 2010 2:50 AM
    • Unmarked as answer by ShukraRai Wednesday, May 5, 2010 3:42 AM
    Wednesday, April 28, 2010 7:56 AM
  • Hi,

    Try this.

     

    dataGridView1.Columns[2].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
    dataGridView1.Columns[2].SortMode = DataGridViewColumnSortMode.NotSortable;
    
    

     

    I don't think this is the answer for the question. Because I don't need my column to be non sortable. I think MS has some explanation regarding this. And this issue is still unresolved. BTW thanks for your time.

    https://connect.microsoft.com/VisualStudio/feedback/details/295106/datagridview-column-headers-alignment-does-not-work-properly-with-center-and-left-align?wa=wsignin1.0

     

    • Marked as answer by Harry Zhu Thursday, May 6, 2010 1:50 AM
    Wednesday, May 5, 2010 3:45 AM
  • Hi,

    Sorry to know the issue has not been resolved.

    I'm going to mark your post as answer since this issue has been reported on connect site and closed.

    Thanks,

    Harry

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Proposed as answer by SFCISoft Monday, May 17, 2010 1:48 PM
    Wednesday, May 5, 2010 4:33 AM