Is there a event detect change of Listview item count? Like it will be trigger whenever i add an item or delete an item form listview. I search on MSDN Listview Event member, but cant c any usefull. Any help would be please:) Thanks


You can try this:

Label1.Text = ListView1.Items.Count()Label1.Text = ListView1.Items.Count()

Errrrr.....actualy wat i need is a listview event which trigger when its Item count(or sub) change. SO it will trigger whenever item is added/deleted from listview.

Sorry for my poor english, hope you can understand what i need:)

If listview dosnt support this event, then i need to assign a timer to do it@@

You could create a function which adds an item and then does whatever post-adding processing you want?

Nevermind. I just use a timer to keep checking to Listview.items.count,If changed then event call.
Just think Listview should have support its "itemchange event",So I need not to do it manually:)

I agree, I would of imagined there would be an event for it.

Are you sure it wouldn't be a better idea to just manually call a function to handle the event though rather than using a timer?

Or maybe create a new class that inherits from the ListView and override the Add method and auto call another method once the item has been added?

I have made you a user control that may get you started on the road to what you want.

Right click your project and add a new User Control, on that user control draw a ListView that covers the entire designer view and call it "lvView".

Now in the code view copy and paste this:

Public Class CustomLV
    Public Sub AddItem(ByVal Item As ListViewItem)
        MessageBox.Show("Add post-adding code here")
    End Sub
End Class

Now you will be able to use the CustomLV control as you would a ListView but you will have access to an AddItem method that will add an item to the encapsulated ListView and will execute whatever code you want afterwards, like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim item As ListViewItem
        item = New ListViewItem("example")
    End Sub

Every time I press the button it will add an item with the text "example" and will automatically show the message box every time I do so. You would also be able to directly access the ListView by using


Hope that helps you achieve what you desire.

Edit: I have attached a ZIP file with the files for this user control in case you have any troubles recreating it yourself.

Yeap, I get what you mean^^ I'm new in VB, Doesn't know it can be done in this way:)

Many thanks, Guess I learn a new technique again O(∩_∩)O擈擈~