Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NullReferenceException when adding item to generic list
#1
I have a little problem that I can't seem to solve.
When I try to add a value (integer) to a generic list (of integer), I always get a NullReferenceException.

This is my code:
[code2=vbnet]Dim listIndexes As List(Of Integer) = Nothing
For Each i As ListViewItem In Me.listKeys.Items
For Each i2 As ListViewItem In Me.listKeys.Items
If i.Text = i2.Text Then
listIndexes.Add(i.Index) 'The error persists here: NullReferenceException
listIndexes.Add(i2.Index) 'and propably an error here too
End If
Next
Next
Me.SelectKeys(listIndexes) 'This line just selects the items in the listview[/code2]

I've discovered that the index of these two items in the listview are both zero.

Hope someone can help,
brco


Messages In This Thread
NullReferenceException when adding item to generic list - by brco900033 - 04-17-2014, 11:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search ListBox + Convert ListBox.item to string brco900033 3 13,803 09-13-2012, 03:03 PM
Last Post: brandonio21
  Change full row select back colour or list view Bradley 3 20,430 05-23-2012, 06:54 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)