Reputation: 1879
I want to update/call some function, when my ListBox.Items.Count
changes. On addition to ListBox
or on removal of the items, how to trigger a function?
Upvotes: 1
Views: 5179
Reputation: 6983
There are no events for this action. You will either need to do one of the following:
really i think 3 is the way to go.
Upvotes: 2
Reputation: 1879
Since I am using AsyncBindingList and which is running on Background Worker thread. And AsyncBindingList is connected to my ListBox. So when my Worker thread finishes its work, it will update AsyncBindingList in return it will update my listBox on the form.
But On addition of items on list box, I was looking for calling a method which updates other controls. so, Finally I got the solution.
Solution is when work thread finishes it's work, it will call RunWorkerCompletedEventHandler. When It calls a Method through RunWorkerCompletedEventHandler, I triggered Forms.Invoke method, which triggered a method on in the form class, which inturn updated all the controls.
But I really don't know is this is the best way to do it. If you have any suggestion. Please post as an answer.
Upvotes: 0
Reputation: 10940
You could use an ObservableCollection as the datasource for the listbox. Then you can create handlers for the CollectionChanged event.
Upvotes: 1