views:

5219

answers:

4

Is there any way to edit column names in a DataGridView?

+2  A: 

I don't think there is a way to do it without writing custom code. I'd implement a ColumnHeaderDoubleClick event handler, and create a TextBox control right on top of the column header.

Muxa
+1  A: 

I guess what you want is to edit the HeaderText property of the column:

myDataGrid.TableStyles[0].GridColumnStyles[0].HeaderText = "My Header"

Source: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=186908&SiteID=1

VVS
+1  A: 

You can also edit directly without knowing anything as posted above :

protected void gvCSMeasureCompare_RowDataBound(object sender, GridViewRowEventArgs e)
     {
      if (e.Row.RowType == DataControlRowType.Header)
       e.Row.Cells[0].Text = "New Header for Column 1";
}
mattlant
+2  A: 

You can also do it with myDataGrid.Columns[0].HeaderText = "My Header", but the myDataGrid will need to have been bound to a DataSource.

Spear