0

I'm trying to write a method for my ComboBoxes that clears their selection if the Text does not match SelectedItem.ToString() - basically clear it if there is text that does not correspond to a ComboBoxItem. However, I'm getting errors upon any attempt to set attributes of the method's sender.

My (reduced) code:

private void Cmbx_LostFocus( object sender, RoutedEventArgs e )
{
    ComboBox _sender = ( ComboBox ) sender;
    _sender.SelectedItem = null;
}

Throws a NullReferenceException when I try to change _sender's SelectedItem or SelectedIndex in any way. I can get these attributes but cannot set them. Why can I not do this?

sirius_pain
  • 31
  • 2
  • 6
  • 21

0 Answers0