Hi, I have two ComboBoxes, one for Organisation and one for Region. When selecting Organisation I want the Region combobox to update itself with the related regions. After selecting Organisation and Region I can type in a Site to a textbox and store it to db (ADD mode). I've completed that with this code:
<ComboBox x:Name="cbOrganisation"
Grid.Row="0"
Grid.Column="1"
ItemsSource="{Binding OrganisationEntries}"
SelectedItem="{Binding SelectedOrganisation, Mode=TwoWay}"
SelectedIndex="{Binding SelectedOrganisationIndex}"
DisplayMemberPath="Description">
</ComboBox>
<ComboBox x:Name="cbRegions"
Grid.Row="1"
Grid.Column="1"
ItemsSource="{Binding ElementName=cbOrganisation, Path=SelectedItem.Regions}"
SelectedItem="{Binding SelectedRegion, Mode=TwoWay}"
SelectedIndex="{Binding SelectedRegionIndex}"
DisplayMemberPath="Description" >
</ComboBox>
So, I'm using element to element binding, with the second combobox having the first one as ItemSource.
Now, I've got a new problem when I want to EDIT a site in my collection. In EDIT mode, I want the two dropdowns to be preselected and disabled (BusinessRule is that I can edit the sitename, not which organisation og region it's connected to). So by setting the SelectedIndex property on Organisation combobox I get my organisation selected, but when doing the same on the Regions combobox it fails with an Object Reference error. Any clue what I'm doing wrong?