views:

3556

answers:

3

Hi,

How to set column header text for specific column in Datagridview C#

+2  A: 

there is HeaderText property in Column object, you can find the column and set its HeaderText after initializing grid or do it in windows form designer via designer for DataGrid.

    public Form1()
    {
        InitializeComponent();

        grid.Columns[0].HeaderText = "First Column"; 
        //..............
    }

More details are here at MSDN. More details about DataGrid are here.

TheVillageIdiot
+1  A: 

grid.Columns[0].HeaderText or grid.Columns["columnname"].HeaderText

Colin
+4  A: 

For info, if you are binding to a class, you can do this in your type via DisplayNameAttribute:

[DisplayName("Access key")]
public string AccessKey { get {...} set {...} }

Now the header-text on auto-generated columns will be "Access key".

Marc Gravell
Wonderful, thanks a lot.
esylvestre