Reputation: 21
I have a problem when try to change datagridview`s column header name.
After i changed the column header name from name Column 1 to Year i am trying to get the value of the cell of that column with command
and it says that Year column cannot be found. I tried the command to row.cells("Column1").value after is changed to Year and it works .
whys that ? is there anything else i have to do in order to save changes ? i can see that the column header name is changed normaly.
Upvotes: 1
Views: 6520
Reputation: 116448
The text in the header, and the column name are two different entities. Changing one does not automatically change the other.
You should refer to the column by it's name, as you have discovered:
row.Cells("Column1").Value
Alternatively, if you want to change the name of the column, you can do so. Assuming you have an underlying DataTable as a data source:
dataTable.Columns("Column1").Name = "MyNewName"
If it's not a data table, you should be able to change the name directly in the DataGridView:
dataGridView.Columns("Column1").Name = "MyNewName"
Upvotes: 1