DataGridView Edit Column Names

一世执手 提交于 2019-11-29 03:57:45

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.

Ryan Spears

You can also change the column name by using:

myDataGrid.Columns[0].HeaderText = "My Header"

but the myDataGrid will need to have been bound to a DataSource.

Bjørn Otto Vasbotten

You can edit the header directly:

dataGridView1.Columns[0].HeaderCell.Value = "Created";
dataGridView1.Columns[1].HeaderCell.Value = "Name";

And so on for as many columns you have.

@Dested if you are populating DataGrid from DataReader, you can change the name of columns in your query

for example

select ID as "Customer ID", CstNm as "First Name", CstLstNm as "Last Name"
from Customers

this way in your data grid you will see Customer ID instead of ID and so forth.

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

mattlant

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";
}

Try this

myDataGrid.Columns[0].HeaderText = "My Header"
myDataGrid.Bind() ;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!