Sam Selikoff
Sam Selikoff

Reputation: 12694

How can I set the content on a BindingList in a way that triggers the change event?

Say I have a List(of company) called companies. I can create a new BindingList from that list like this:

blCompanies = New BindingList(of company)(companies)

But, what if I have an empty binding list

newBL = New BindingList(of company)

How can I add all the companies from companies to this list in a way that newBL will throw its change event?

Upvotes: 1

Views: 279

Answers (1)

Steven Doggart
Steven Doggart

Reputation: 43743

Since the BindingList doesn't have an AddRange method, you'll need to call the Add method separately for each item you want to add, for instance:

For Each i As company In companies
    blCompanies.Add(i)
Next

Or:

companies.ForEach(Sub(x) blCompanies.Add(x))

Note, when you call the Add method, it will raise the ListChanged event, but not the AddingNew event. The AddingNew event is only raised when you call the AddNew method. If you need to determine what type of change happened when you are in the ListChanged event handler, you'll need to check the value of the e.ListChangedType property.

Upvotes: 2

Related Questions