Possible Duplicate:
What is a NullReferenceException in .NET?
I have two ComboBoxes, one of companies and other of regions (meaning each company has a set o regions) and I want to change the ItemSource of the ComboBox_Region in accordance with the company set at ComboBox_Company.
I have two classes, representing the companies and regions, and a method of region class that returns the list of regions of determined company (passed as parameter).
I have also an event treggered when the ComboBox_Company selected item is changed that should reload the ComboBox_Region source. See below
private void ComboBox_Company_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Company selected_company= (Company)ComboBox_Company.SelectedValue;
Dictionary<int, string> regions = Region.GetLookupListByCompanyID(null, selected_company.ID, false);
ComboBox_Region.ItemsSource = regions.Values;
}
Nevertheless, I got an NullReferenceException error and I don't know how to solve it.
And here goes the XAML code:
<TextBlock Grid.Row="0" Grid.Column="0" Text="{x:Static props:ResourcesWPF.Company}" />
<ComboBox Name="ComboBox_Company" Grid.Row="0" Grid.Column="1" DisplayMemberPath="Name" SelectedItem="ID" Initialized="ComboBox_Company_Initialized" SelectionChanged="ComboBox_Company_SelectionChanged" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="{x:Static props:ResourcesWPF.Region}" />
<ComboBox Name="ComboBox_Region" Grid.Row="1" Grid.Column="1" DisplayMemberPath="Name" SelectedItem="ID" Initialized="ComboBox_Region_Initialized" SelectionChanged="ComboBox_Region_SelectionChanged" />