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

前端 未结 4 1500
佛祖请我去吃肉
佛祖请我去吃肉 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 16:59

    This solution seems to work - in my situation, I implemented it in VB. I just created an ExtendedListbox class which inherits the listbox control, implements INotifyPropertyChanged and shadows the Items Property.

    Imports System.ComponentModel
    
    Public Class ExtendedListBox:Inherits ListBox:Implements INotifyPropertyChanged
    
        Public Shadows Property Items() As ObjectCollection
            Get
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Items"))
                Return MyBase.Items
            End Get
            Set(value As ObjectCollection)
                RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("Items"))
                MyBase.Items.Clear()
                For Each o As Object In value
                    MyBase.Items.Add(o)
                Next
            End Set
        End Property
    
        Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged
    End Class
    

提交回复
热议问题