I have a form where the first question is, does the person want to answer these questions? If it equals "No" then hide the other inputs. When i hide the inputs i want to erase the fields so they are blank.
When i hide my combobox and use: calledUs.SelectedIndex = -1;
it returns an error saying
Object reference not set to an instance of an object
but it does what i want it to, just with an error.
Am i missing something to overcome the Null reference? I have been reading the following Stack Overflow questions:
Combobox text when clearing items
What is a NullReferenceException, and how do I fix it?
Any help would be great.
UPDATE:
Code Example:
private void wantToAnswer_SelectedIndexChanged(object sender, EventArgs e)
{
if (wantToAnswer.SelectedItem.ToString() == "Yes")
{
//THIS IS THE PANEL THE COMBOBOX IS WITHIN
clothingCaughtFire.Visible = true;
Refresh();
}
else
{
calledUs.SelectedIndex = -1;
//THIS IS THE PANEL THE COMBOBOX IS WITHIN
clothingCaughtFire.Visible = false;
Refresh();
}
}