Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
listviewcontrol.Items.IndexOf(string) null reference exception in C# even when listview items count is non zero. if i enter listviewcontrol.Items.IndexOf("") it returnes -1 but if i provide any sting it will throw null reference exception. please suggest.
Posted
Comments
Praveen Kumar Upadhyay 23-Dec-14 1:53am    
Please show your code.

1 solution

ListView.ListViewItemCollection.IndexOf(parameter) requires a parameter that is a ListViewItem.

ListViewItem.ListViewItemCollection.IndexOfKey(parameter) takes a string argument and will return the ListViewItem whose key (Name) property matches the Item.

ListView.ListViewItemCollection[parameter] can take a string, or an Int32 argument. If the argument is a string, then it will return the ListViewItem whose key (Name) property matches the string; if an Int32, it will return the ListViewItem at the index specified by the Int32.

Set a break-point at a place where you can examine what the ListViewItems in your ListView are now: look at their 'Name property, and use what you see, and the information given above to figure out why you observe the behavior that your report.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900