I've got a form with some details for a person. I pick up the values on the form and pass them into a person class. What I want to do is open another form and pick up the values I've passed into the Person class, but I'm getting the error... "No overload for method 'frmInvoice' takes '1' argument"
string pName = this.txtName.Text.ToUpper();
string pAddress = this.txtAddress.Text.ToUpper();
string pStatus = this.cboStatus.Text.Substring(0, 1).ToUpper();
DateTime pDoB = DateTime.Parse(this.txtDoB.Text);
//Person Details
Person pPerson = new Person(pName, pDoB, pAddress, pStatus);
//Creates new instance of Invoice form and Pass person class to it
frmInvoice invForm = new frmInvoice(pPerson);
invForm.Show();
Any ideas?
Thanks in advance.
Roy
AlanPosted Mar 19, 2008, 1:40 PM
It's sounds as though you haven't got frmInvoice's constructor set up to accept a parameter of type Person. At the moment the constructor will probably look like this:
public frmInvoice()
{
InitializeComponent();
}
Provided you're never to going to start up the form without passing it a Person object, then change it to this:
// private field to store Person object passed to constructor
private Person person;
public frmInvoice(Person person)
{
InitializeComponent();
this.person = person;
}
If you may start up the form without passing it a Person object, then leave the present constructor alone but add the following overload:
public frmInvoice(Person person) : this()
{
this.person = person;
}