OK this works...,
But isn't there a simpler way to do the same thing?
I tried it like this, no syntax errors,..
But both fail to run, Object reference not set to an instance of an object.
Code:
' setup LV
ListView1.View = View.Details
ListView1.AllowColumnReorder = True
ListView1.Columns.Add("A")
ListView1.Columns.Add("B")
ListView1.Columns.Add("C")
' Get column index by column header text
Dim i As Integer = GetLvColumnIndex(Me.ListView1, "B")
Debug.WriteLine(i)
Private Function GetLvColumnIndex(LV As ListView, HeaderText As String) As Integer
For Each c As ColumnHeader In LV.Columns
If c.Text = HeaderText Then
Return c.DisplayIndex
End If
Next c
Return -1
End Function
I tried it like this, no syntax errors,..
Code:
Dim j As Integer = Me.ListView1.Columns("B").DisplayIndex
Dim i As Integer = Me.ListView1.Columns.Item("B").DisplayIndex