Is there an event that triggers if the number of ListViewItems in a ListView changes? (Windows Forms)

后端 未结 3 1628
一个人的身影
一个人的身影 2021-01-20 20:39

I\'d like to enable/disable some other controls based on how many items are in my ListView control. I can\'t find any event that would do this, either on the

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-20 21:30

    I can't find any events that you could use. Perhaps you could subclass ListViewItemCollection, and raise your own event when something is added, with code similar to this.

    Public Class MyListViewItemCollection
        Inherits ListView.ListViewItemCollection
    
        Public Event ItemAdded(ByVal Item As ListViewItem)
    
        Sub New(ByVal owner As ListView)
            MyBase.New(owner)
        End Sub
    
        Public Overrides Function Add(ByVal value As System.Windows.Forms.ListViewItem) As System.Windows.Forms.ListViewItem
            Dim Item As ListViewItem
    
            Item = MyBase.Add(value)
    
            RaiseEvent ItemAdded(Item)
    
            Return Item
        End Function
    End Class
    

提交回复
热议问题