Search code examples
c#eventsonchange

c#, is there OnChange event in ListBox?


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)


Solution

  • You can use the SelectedIndexChanged or SelectedValueChanged events.

    For adding or removing items there are no .NET events, so you have to implement that functionality yourself. This SO post explains how you can accomplish that.

    Good luck!

    PS: I assumed you are using Windows Forms