Change gridview padding left for all rows except the column header

youki 1,021 Reputation points
2021-01-09T00:46:42.067+00:00

Can i simply change it only for the header?
(If the header text is bold, the row text is too much on the left side.)

The following doesn't work:

for (int i = 0; i < gvTitles.Rows.Count; i++)
{
      gvTitles.Rows[i].DefaultCellStyle.Padding = new Padding(30, 0, 0, 0);
}

https://social.msdn.microsoft.com/Forums/windows/en-US/a9227253-8bb4-429a-a700-8a3a255afe4d/how-to-change-padding-of-specific-rowcolumn-in-datagridview?forum=winforms

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,903 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118K Reputation points
    2021-01-09T10:25:22.317+00:00

    To change the padding of all header cells, try this:

    gvTitles.ColumnHeadersDefaultCellStyle.Padding = new Padding( 10, 0, 0, 0 );
    

1 additional answer

Sort by: Most helpful
  1. Abdulhakim M. Elrhumi 356 Reputation points
    2021-01-09T13:06:42.287+00:00

    Hi

    DataGridViewCellStyle.Padding Property
    system.windows.forms.datagridviewcellstyle.padding

    Best Regards.

    Please click the Mark as answer button and vote as helpful if this reply solves your problem.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.