Reputation: 4997
I have a listview with several columns. I want to change the column header using code. Please advise how to do it.
Upvotes: 3
Views: 16284
Reputation: 11
In a List View, there is a difference between Column Header .Name and Column Header .Text.
The .Text is displayed at the top of the List View. The .Name is the Column Name which you can refer to in your code. If you try to get the ListView1.Columns(0).Name in your code, it will always be "". Unless, during the design time, in the edit column header properties, you set Under Data, Application Settings, and Properties Binding, the DisplayIndex Name Default Value is the .Name value.
Upvotes: 0
Reputation: 64
To change the header name, you have to use the name property
Listview1.columns(0).name = "column1Name"
But you can also assign the column name while assigning it's "text" value
Listview1.Columns.add("Column1text").name = "Column1Name"
You can then use it's name to refer to it
Listview1.columns.item(Listview1.columns("Column1Name").index).text = "Column1TextChanged"
Upvotes: -1
Reputation: 13775
I just tested ListView1.Columns(0).Text = "changed"
and it worked. This is VB.Net, winforms, VS 2010.
Upvotes: 5