How can I add a newline character to the HeaderText of a DataGridView control?

Spideregg 140 Reputation points

I have applied this for the DataGridView control in the above image, but I would like the resulting output to be displayed as shown below.


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.
10,483 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 41,426 Reputation points Microsoft Vendor

    Hi @Spideregg , Welcome to Microsoft Q&A.

    You need to modify the property of DataGridView.DefaultCellStyle.WrapMode to DataGridViewTriState.True.

    For example as follows:

    dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
    dataGridView1.Columns[0].HeaderText = "Student\nname";

    enter image description here

    Best Regards,


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Spideregg 140 Reputation points

    You can try WrapMode = true

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    Comments have been turned off. Learn more