Question : VB.NET: ListView FindItemWithText returns exception

Hi X-perts,

My code throws an exception with a message "Object reference not set to an instance of an object.", if a text string is not found. How can I avoid it without using Try/Catch?


Thanks
Code Snippet:
1:
2:
3:
4:
5:
6:
If Not (rc.EOF And rc.BOF) Then
                For Each f In rc.Fields
                    j = Me.ListView2.FindItemWithText(f.Name).Index '==> Error!
                    If (j <> -1) Then Me.ListView2.Items(j).Checked = True
                Next
            End If

Answer : VB.NET: ListView FindItemWithText returns exception

The another reason of getting this error may be...
You are trying to FindItemWithText() which is not in listview at all.
Random Solutions  
 
programming4us programming4us