The new Form1() part of this code (this code is in my Main.cs) keeps giving me this error – HomeInventory2.Form1 does not contain a constructor that takes 0 arguments.
private void cDsToolStripMenuItem_Click(object sender, EventArgs e)
{
var form = new Form1();
// show the form
form.Show();
}
The Form1 code is as follows
namespace HomeInventory2
{
public partial class Form1 : Form
{
public Form1(IEnumerable<string> prepopulated)
{
InitializeComponent();
IEnumerable<String> lines = prepopulated;
textBoxAmount.Text = lines.ElementAtOrDefault(0);
textBoxCategories.Text = lines.ElementAtOrDefault(1);
textBoxProperties.Text = lines.ElementAtOrDefault(2);
textBoxValue.Text = lines.ElementAtOrDefault(3);
}
private void label1_Click(object sender, EventArgs e)
{
}
private void submitButton_Click(object sender, EventArgs e)
{
CreateInventory create = new CreateInventory();
create.ItemAmount = textBoxAmount.Text;
create.ItemCategory = textBoxCategories.Text;
create.ItemProperties = textBoxValue.Text;
create.ItemValue = textBoxValue.Text;
InventoryMngr invtryMngr = new InventoryMngr();
invtryMngr.Create(create);
}
}
}
I tried just putting a blank constructor in there – but then of course when that button or menu item is called it just brings up a blank screen.
All classes in .net have default constructors which don’t take any arguments. When you are implementing your own constructor then the framework doesn’t generate that empty constructor for your class. Same thing is happening here. in you
cDsToolStripMenuItem_Clickmethod you need to passIEnumerable<string>parameter.