How to change header text in DatagridView - in code C#?

If you are using data-binding to a type and auto-generated columns, this is the [DisplayName(...)], i.e.

[DisplayName("Last name")]
public string LastName {get;set;}

Otherwise this is the HeaderText on the column, i.e.

grid.Columns[0].HeaderText = "Something special";

A basic way to add a column is:

int columnIndex = grid.Columns.Add("columnName", "Header Text");

Or you can be more specific, for example to add a column of hyperlinks:

grid.Columns.Add(new DataGridViewLinkColumn());

(you could obviously set more properties on the new column first)

Tags:

C#

Winforms