I am having an issue where the base constructor for a derived class is not getting executed. I have done this a hundred times and I cannot figure out for the life of me why the base constructor is not executing. I'm hoping that someone can find something simple that I am missing. An example of the code is below. Does anyone have any idea why my base constructor is not getting called first? I have other classes that are implemented in the same fashion and the base constructor is always called first.
if (item.GetType() == typeof(OtherChargeItem))
{
OtherChargeItemAddUpdateTest test = new OtherChargeItemAddUpdateTest((OtherChargeItem)item);
test.StartPosition = FormStartPosition.CenterParent;
test.ShowDialog();
}
public OtherChargeItemAddUpdateTest()
{
InitializeComponent();
}
public OtherChargeItemAddUpdateTest(OtherChargeItem item)
: base()
{
currentItem = item;
}
It looks like you want to call the default constructor in the same class, not the base class, so InitializeComponent
gets called when the second constructor gets called. Try this()
instead of base()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With