SupremeUK
October 19th, 2007, 10:33 AM
Hi all
I'm building a little windows form app in C#, MSVS 2005, .NET 2.0.5 where I have a form, and then a panel on the form, which changes if buttons on the form are clicked, or if an item is selected in the panel, and it works great with the first panel change, but on the second panel change, it gives me a "System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
It happens on this on the last part of this user control:
namespace PeteDoorProject
{
public partial class setup : UserControl
{
public setup()
{
InitializeComponent();
}
public void ddNumbers_SelectedIndexChanged(object sender, EventArgs e)
{
//int intNumberOfBoxes = int.Parse(ddNumbers.SelectedItem.ToString());
setupTwo objSetupTwo = new setupTwo();
this.Parent.Controls.Clear();
this.Parent.Controls.Add(objSetupTwo); // <------ exception here
}
}
}
So basically, what is supposed to happen is:
1. Someone clicks a button on the form1, and it loads setup.cs to the panel
2. setup.cs has a combobox, and when someone selects a number, it should load setupTwo onto the parent panel.
Any help would be greatly appreciated.
Thanks
I'm building a little windows form app in C#, MSVS 2005, .NET 2.0.5 where I have a form, and then a panel on the form, which changes if buttons on the form are clicked, or if an item is selected in the panel, and it works great with the first panel change, but on the second panel change, it gives me a "System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
It happens on this on the last part of this user control:
namespace PeteDoorProject
{
public partial class setup : UserControl
{
public setup()
{
InitializeComponent();
}
public void ddNumbers_SelectedIndexChanged(object sender, EventArgs e)
{
//int intNumberOfBoxes = int.Parse(ddNumbers.SelectedItem.ToString());
setupTwo objSetupTwo = new setupTwo();
this.Parent.Controls.Clear();
this.Parent.Controls.Add(objSetupTwo); // <------ exception here
}
}
}
So basically, what is supposed to happen is:
1. Someone clicks a button on the form1, and it loads setup.cs to the panel
2. setup.cs has a combobox, and when someone selects a number, it should load setupTwo onto the parent panel.
Any help would be greatly appreciated.
Thanks