c#, is there OnChange event in ListBox?
17,611
If you're binding your ListBox
to say a BindingList
, you can use the BindingLists
's ListChanged
event. The ListChangedEventArgs
has an argument ListChangedType
which tells you if an item was added, removed, moved or changed.
You can do similar things with similar collections.
If you're adding or removing items yourself, you can obviously directly tell some other piece of code to execute or you can just create and raise an event yourself, provided you have a ListAdded
event:
ListAdded(this, new ListAddedEventArgs() { List = myList, Item = myItem });
![Patryk](https://i.stack.imgur.com/Fmf8s.png?s=256&g=1)
Comments
-
Patryk about 2 years
I've been looking for something like that but I couldn't find it. I want my program to do something when there's any change in
ListBox
(e.g. changing selected item, adding new one, removing one and so on)