Can someone help me please. Ive got a listview with the columns etc, when i save a form and it shows up in the listview with some items in the columns, how can i get a textbox to add a number each time a row is entered.

example: I save a form into the listveiew and it counts how many i have in the list.


I assume you have a line of code somewhere to add the new row to the ListView similar to


Why can't you add a line after that like

TextBox1.Text = "# of rows is " & ListView1.Items.Count.ToString()

Why not? It works for me. How are you adding rows to the ListView and in what way didn't it work?

This is the code im using to add the items to a listview from a form:

Dim item As New ListViewItem(TextBox1.Text)
        IRSMS.ListView1.Items.AddRange(New ListViewItem() {item})

Just add

txtNumRows.Text = "# of rows is " & ListView1.Items.Count.ToString()

after line 10. By the way. You can simplify line 10 to


As you can probably tell, im new to this aha i dont get where i put the code snippet?

i tried adding it to the listview but the word txtnumrows has a red line beneath it saying i should create a method snub for it

I assume txtNumRows is supposed to be a Textbox on your form to display the number of rows...

txtNumRows was a TextBox control I added to my test form to display the result. You can replace it with a control (possible Label) of your choice. I usually prefix my controls with an identifier for the type of control such as

lbl = Label
lvw = ListView
dgv = DatGridView
txt = TextBox
btn = Button

txtNumRows would be the name of your textbox where you want to display the count.

The (normal) naming convention for vb.net would be object type|name(camel case)

So txt = TextBox


Dim sHello As String = "Hello, World!"
'Note the s prefix

Dim iCount As Integer
'Note the i prefix

Dim bApprove As Boolean
'Note the b prefix

Therefore something named:


Would be a label (lbl)

What part of

txtNumRows was a TextBox control I added to my test form to display the result

could possibly be unclear?

all this is great, but im still stuck on how i can get a textbox to show how many items i have in a listview, if we could possibly focus on that i would be greatful :)

If you don't know enough about programming and Visual Basic to be able to understand the help you've been given then it is time to 86 the computer and take up basket weaving.

Jim has provided ample code for displaying the item count of a listview. He has all but write the code (in project) for you. What about the code are you not understanding?

His code seems clear enough to understand. If it's the names of his variables/objects - just rename them to what you need, et voila.