Furqan Sehgal
Furqan Sehgal

Reputation: 4997

Changing Column header name of ListView using vb.net code

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

Answers (3)

AY_NZ
AY_NZ

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.

ColumnHeader Properties

Upvotes: 0

Mathieu
Mathieu

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

Yatrix
Yatrix

Reputation: 13775

I just tested ListView1.Columns(0).Text = "changed" and it worked. This is VB.Net, winforms, VS 2010.

Upvotes: 5

Related Questions