Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When try to access newly added value in the combo box it gives this error message!

Object reference not set to an instance of an object

window have one combo box and text box! when click the Add new item button, text box value should be loaded in to the combo box.! This loaded action working fine! but when we try to access the newly added one( for example when click edit button) , above error message displayed.

XMAL Code
XML
<ComboBox x:Name="cmbList"  x:FieldModifier="public" HorizontalAlignment="Left" Margin="58,10,0,0" VerticalAlignment="Top" Width="147" 
                    <ComboBoxItem Content="1st Item"/>
                    <ComboBoxItem Content="2nd Item"/>
                    <ComboBoxItem Content="3rd Item"/>
 </ComboBox>


button click function
C#
cmbList.Items.Add(textbox1.text)


What I have tried:

Up to add new item ,it working properly! If I try to re select it gives this error message!

Please anyone correct me!

Thanks in Advance!
Posted
Updated 11-Aug-16 1:04am
Comments
[no name] 11-Aug-16 7:16am    
What you mean exactly with "When try to Access newly added value"? How What is the code which accesses the value from the Combobox?

1 solution

Use your debugger to step through the code and see which of the two objects does not contain a valid reference.

For completeness I just tried that code in a simple WPF application and it works correctly. So your code must be different to what you have posted.
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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