I have a problem with the set of a default value for a combobox :
<ComboBox x:Name="cmbAuthentification" Height="20" Grid.Row="1" Grid.Column="1" BorderBrush="#FF2BBFF0" FontFamily="Segoe UI Light" IsReadOnly="True" SelectionChanged="cmbAuthentification_SelectionChanged">
<ComboBoxItem>Windows</ComboBoxItem>
<ComboBoxItem>SQL Server</ComboBoxItem>
</ComboBox>
In the xmal, I have this code :
private void cmbAuthentification_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (cmbAuthentification.SelectedIndex == 0)
{
txtUserID.IsEnabled = false;
txtUserID.Clear();
txtUserPwd.IsEnabled = false;
txtUserPwd.Clear();
}
if (cmbAuthentification.SelectedIndex == 1)
{
txtUserID.IsEnabled = true;
txtUserPwd.IsEnabled = true;
}
}
When I try to set SelectedIndex="0" in the ComboBox, I have an error at runtime : NullReferenceException : Object reference not set to an instance of an object.