• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

Need help to programatically drop a column from Listview

I am using VB.Net 2005

I want to drop a column from a listview. My code is throwing an error and I don't know why. Please help me fix it.

I put a message beside the offending line in the code. The error reads:

Null Reference Exception was unhandled.
Object reference not set to an instance of an object.

Thanks

PBLack

        Dim column As ColumnHeader
        For Each column In lvTreeVol.Columns
            Dim instance As ListView.ColumnHeaderCollection
            If column.Text = "Block" Then
                instance.Remove(column) ' error thown here
            End If
        Next
0
PBLack
Asked:
PBLack
1 Solution
 
PaulHewsCommented:
Try:

        Dim column As ColumnHeader
        For Each column In lvTreeVol.Columns
            If column.Text = "Block" Then
                lvTreeVol.Columns.Remove(column)
            End If
        Next
0
 
PBLackAuthor Commented:
Perfect. Thanks
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now