Click here to Skip to main content
15,922,155 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
string s=ListBox1.SelectedItem.Value.ToString();
Error:

Object reference not set to an instance of an object.
Posted
Comments
[no name] 17-Jul-15 10:07am    
Think about that it can be, that there is no item selected...

1 solution

Maybe:
if (ListBox1.SelectedItem != null) {
   string s = ListBox1.SelectedItem.Value.ToString();
}

You should learn how to debug your project; that would have allowed you to point out and solve the problem in no time.
 
Share this answer
 
Comments
Member 11804811 17-Jul-15 10:18am    
I selected a item and rather it show this Exception And Know the Debugging also.
Member 11804811 17-Jul-15 10:19am    
When i Debug It show this Error
phil.o 17-Jul-15 10:25am    
Then maybe try to use SelectedValue instead of SelectedItem. What are the values of each of these properties while you debug?
Member 11804811 17-Jul-15 10:46am    
Okk....Let me check..

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