goamn
goamn

Reputation: 2136

C# How do I get the ColumnHeader of a ListViewItem?

I haven't found the answer anywhere. How do I get the ColumnHeader of a given ListViewItem?

The context is that I am inside the ListViewColumnSorter (custom code). I have access to two ListViewItem's, how can I get the ColumnHeader? I need to access the column's tag which contains information I put in there through the VS designer.

Upvotes: 0

Views: 341

Answers (1)

itsme86
itsme86

Reputation: 19526

The ListViewItem spans all columns in the ListView (e.g. lvItem.SubItems[0] is column 1, lvItem.SubItems[1] is column 2, etc. You should know the column number you're sorting by. Then you can trace back through the ListView property:

ColumnHeader = lvItem.ListView.Columns[columnNumber];

Upvotes: 1

Related Questions