0
votes

I have the following 2 classes:

public class CustomerList
{
    public string Name { get; set; }
    public ICollection<Customer> Customers { get; set; }

    public CustomerList()
    {
        Customers = new List<Customer>();
    }
}

public class Customer
{
    public string Name { get; set; }
    public string Surname { get; set; }
}

I have a form with a binding source, listview and 2 textbox controls. The datasource for the bindingsource if Customer. The datasource for the listview is the bindingsource itself, whilst the databindings for the textbox controls are the respective customer properties.

At runtime, the bindingsource datasource changes to:

customerList = new CustomerList();
bindingSource.Datasource = customerList.Customers;

I then start entering text in the controls and on click the Save button, I call 'bindingSource.EndEdit()'. However nothing is added?

Is this not the correct way to use a bindingsource with a list and editing controls?

1

1 Answers

0
votes

If you change your CustomerList to an ObservableCollection it will work. The observablecollection will be able to notify the ListView when items are changed, added and deleted.

It MAY also require that you add "mode=twoway" to your binding expression on the TextBox, I dont remember that off the top of my head.