-1

I have a problem with radiobutton. Application uses it when reading data from the database. Reads the user's gender. This function works when a user is logged on and selects the appropriate button. The first time you read correctly, but the second program returns an exception NullReferenceException was unhandled.

C#

 if (napis.ItemArray.GetValue(5).ToString() == "Mężczyzna")
        {
            MezczyznaRadioButton2.IsChecked = true;
            KobietaRadioButton2.IsChecked = false;
        }
        else
        {
            KobietaRadioButton2.IsChecked = true;
            MezczyznaRadioButton2.IsChecked = false;
        }
user231605
  • 159
  • 1
  • 3
  • 10

1 Answers1

1

One of the following are null:

  • napis
  • napis.ItemArray
  • napis.ItemArray.GetValue(5) - the return value would be null here

Use the debugger to determine that.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232