Question

I'm trying to move items to a listbox, but it's calling my listbox a method group. The program has multiple classes. Here's what I have at the moment...

private void Button1_Click(object sender, EventArgs e)
{
    ListBox1.Items.Add("Full Name\tAddress\tPhone Number");

    Person Customer = new Person();
    Customer.FirstName = NameTextBox.Text;
    Customer.LastName = NameTextBox2.Text;
    Customer.Address = AddressTextBox.Text + AddressTextBox2.Text + AddressTextBox3.Text;
    Customer.PhoneNumber = PhoneNumberMaskedTextBox.Text;

    Listbox1.Items.Add = (Customer.FirstName + Customer.LastName + "/t" + Customer.Address + "/t" + Customer.PhoneNumber);
}

Person is another class. Here's the code for that...

class Person
{
    string _FirstName;
    string _LastName;
    string _Address;
    string _PhoneNumber;

    //Constructor
    public void CustomerInfo()
    {
        _FirstName = "";
        _LastName = "";
        _Address = "";
        _PhoneNumber = "";
    }

    public string FirstName           
    {
      get { return _FirstName; }
      set { _FirstName = value; }
    }

    public string LastName
    {
      get { return _LastName; }
      set { _LastName = value; }
    }

    public string Address
    {
      get { return _Address; }
      set { _Address = value; }
    }

    public string PhoneNumber
    {
        get { return _PhoneNumber; }
        set { _PhoneNumber = value; }
    }
}
Was it helpful?

Solution

In yor second Add call probably you wanted to have

Listbox1.Items.Add(...)

instead of

Listbox1.Items.Add = (

Something else incorrect on your code is constructor name for Person. It should be named Person since contructors have same name as the class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top