Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have been searching for an event to use while displaying in a label the total count of items in my listview. The label is ok but i've tried a list of events. non are working. Are there any suggested methods?
Posted
Comments
Rajesh Anuhya 24-Jun-13 11:16am    
Not clear
jenitshah 25-Jun-13 0:10am    
Do you mean... Label should display number of items in listview whenever Listview got added or removed any item?
dflo 25-Jun-13 3:49am    
yes, i've already done this. what i need is to get the count of the items once they're added or removed from the listview!

There is no event for an item being added/removed from a ListView. But there is something you can do about it...

You can create a new ListView control, deriving from ListView, and add a method to it for AddItem and RemoveItem. In these methods, you add/remove the item to the Items list, and raise your own event for an ItemsChanged or something similiar.

I apologize that I can't post code to do this, I'm not very good in VB. Hopefully somebody else can give you a working example, it doesn't take much code to do it.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 24-Jun-13 12:59pm    
I voted 5 for this as a guesswork. You guess looks reasonable, but it is not 100% apparent that this is what OP needs, formally, that's not it, but OP doesn't seem to understand what's really needed. I don't think showing any code would worth the effort.
—SA
create a timer from toolbox and set interval to 1000
under the tick_event of the timer1
just write this code
VB
Static x As Integer = 0
        If ListView1.Items.Count > x Then
            x += Val(ListView1.Items.Count - x)
        ElseIf ListView1.Items.Count < x Then
            x -= Val(x - ListView1.Items.Count)
        End If
        Label1.Text = x


please make sure you flag this as solved if it helped you....happy coding
 
Share this answer
 
v2
Comments
dflo 28-Jun-13 13:02pm    
Thanks for this but i cannot understand the ComboBox part. why ComboBox? i do not have a ComboBox on my form. just need to display total rows count (like 25 items) on a label anytime an item is added/remove from ListView.
Member 9195998 30-Jun-13 16:47pm    
sorry man just change the combobox1 to listview1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900