Click here to Skip to main content
15,790,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I am developing a windows 8.1 application . For this I am in a need of list box with check boxes . I implemented all the code for this . My problem is I want to iterate the list box items . While doing this I am getting error like null reference exception.

My code is...

foreach(Classes.FilterOperators li in listOperators.Items)
                       ListBoxItem checedItem2 = this.listOperators.ItemContainerGenerator.ContainerFromItem(li) as ListBoxItem;
                       checedItem2.IsSelected = true;

I am getting the error in the loop at 2nd line.

I don't know how to iterate the loop any help...

Tejas Vaishnav 20-Jan-15 5:42am    
i think your first like which is creating listboxitem is not returning any value, and you checedItem2 is remain, null that's why our got null reference exception on second line.
SureshMarepalli 20-Jan-15 6:39am    
ok , can you help me how to iterate it.

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