Click here to Skip to main content
15,922,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,

In my WPF Application, I have few controls viz., List Box(A) and ComboBox(B) and TextBox(C), I need to disable the entities, ie., If User selects (A) any value from List Box, Both items in ComboBox and TextBox should be disabled and vice versa.

For Instance,using SelectionChanged property for Listbox, intended to disable two other controls(viz., ComboBx, TextBx) using the below code behind. and xaml code

//MyFile.xaml
HTML
<ListBox Name="MyListBox"  SelectionChanged="ListBx_SelectionChanged"  ...>
.....


//MyFile.xaml.cs
C#
private void ListBx_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    MyTextbx.IsEnabled = false;
    MyComboBx.IsEnabled = false;
}


I get assertion on above change, Please let me know we can resolve the same? or any other alternative approach to target the above problem. The Exception of type "System.NullReferenceException" occurred, and was not handled in user code. Additional Information: Object Reference not set to an Instance of an Object.


Any Help in resolving the above would be appreciable.
Posted
Updated 25-Mar-12 23:45pm
v3

1 solution

Probably MyTextbx and MyComboBx not been yet initialized when the ListBx_SelectionChanged is handled.
Try to check MyTextbx and MyComboBx for null
private void ListBx_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  if(MyTextbx!=null && MyComboBx!=null)
   {
    MyTextbx.IsEnabled = false;
    MyComboBx.IsEnabled = false;
   }
}
 
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