By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,571 Members | 1,669 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,571 IT Pros & Developers. It's quick & easy.

Listview item add in loop

P: n/a
rr
I have a list view with several rows and would like to populate it using a
loop. However when I try to use a variable in the obejct name it fails and
says obejct
doest exist. Is there some object id cat operator?

Here is a snippet:

Dim item1 As New ListViewItem("stuff1")
Dim item2 As New ListViewItem("stuff2")
Dim item3 As New ListViewItem("stuff3")
Dim item4 As New ListViewItem("stuff4")

Dim i as Integer

for i=0

If Not PingPC(item + cstr(i).Text) Then
RowColor(item + cstr (i))
Else
InsertIp(item + cstr (i))
End If

next

It fails stating there is no itemi, I have also tried item + cstr(i)
Any suggestions or otyher ways to populate a listview.

thanks
Robert
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Robert.

Rather than use a set of independant Item variables, why not use an array?

Dim item (3) As ListViewItem
item (0) = New ListViewItem("stuff1")
item (1) = New ListViewItem("stuff2")
item (2) = New ListViewItem("stuff3")
item (3) = New ListViewItem("stuff4")

for i=0
If Not PingPC(item (i).Text) Then
RowColor(item (i))
Else
InsertIp(item (i))
End If
next

I noticed that your question refers to populating the ListView with a loop
but that your code doesn't. I have followed the code assuming, lol, that the
'documentation' is out of synch.

If you want "stuff1", "stuff", etc inside a loop, you'll have to let me
know.

Regards,
Fergus
Nov 20 '05 #2

P: n/a
Cor
Hi Rolls Roys,

In addition to Fergus, here a sample of a way to do a for each loop in a
listview

Dim vItem As ListViewItem
Dim vcolor As System.Drawing.Color = System.Drawing.Color.Blue
For Each vItem In ListView1.Items
If vcolor.ToString = System.Drawing.Color.Blue.ToString Then
vcolor = System.Drawing.Color.Red
Else
vcolor = System.Drawing.Color.Blue
End If
vItem.SubItems(0).BackColor = vcolor
Next
I hope this helps a little bit
Cor
Nov 20 '05 #3

P: n/a
rr
Thanks for the replies, I will give them a try on Monday.

The code was a bitt off as it was late Friday and I took the loop out
earlier because it didnt work. I wrote it back in from memroy.

I am trying to populate the listviews first column with static data. The
other other colums are dynamic data from functions..

thanks for your help
robert
"Cor" <no*@non.com> wrote in message
news:3f***********************@reader20.wxs.nl...
Hi Rolls Roys,

In addition to Fergus, here a sample of a way to do a for each loop in a
listview

Dim vItem As ListViewItem
Dim vcolor As System.Drawing.Color = System.Drawing.Color.Blue
For Each vItem In ListView1.Items
If vcolor.ToString = System.Drawing.Color.Blue.ToString Then
vcolor = System.Drawing.Color.Red
Else
vcolor = System.Drawing.Color.Blue
End If
vItem.SubItems(0).BackColor = vcolor
Next
I hope this helps a little bit
Cor

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.