How to detect if items are added to a ListBox (or CheckedListBox) control

前端 未结 4 1492
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 16:38

This seems like a fundamentally simple question. I have a WinForms dialog box with a listbox. This control is not populated via data-binding but is filled with call

4条回答
  •  遥遥无期
    2020-12-09 17:03

    I don't know of any event that you can watch to show that an item has been added to a ListBox. Perhaps you can use the Win32 method you described instead (i.e. grab a handle, use WndProc, etc.).

    Alternately, perhaps you can use another class that adds items instead. For example, rather than calling the Add method on the ListBox directly, you could have user-actions call the Add method inside the new class which then adds the item to the ListBox. You could set an event inside that class that would allow you to watch what's been added.

    I also like the idea of subclassing the ListBox as mentioned by another poster....

提交回复
热议问题