473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Listview item add in loop

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
3 6988
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: VM | last post by:
How can I fill up a listview with text file contents? My listview has two columns and the first column fills up with a while loop: while (myString != null) { myString = sr.Readline();...
3
by: PL | last post by:
Hi, ListView doesn't seem to have the FindItem function anymore. What are you using instead of that method (other than foreach in the ListView.Items)? Thanks! PL
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
3
by: amber | last post by:
I have a listview (lstvwAmend) (containing 2 columns) that is populated by a filtered dataview (dvRPA) that is based on a dataset (dsRPAmend1) pulling data from a SQL Server database This dataview...
3
by: | last post by:
Hello, I have a ListView control in Details view. When an item is un-checked, I want to change the ForeColor. The only way I have found to do this is to loop through all the items of the...
2
by: Mamatha | last post by:
Hi I have an application with listview.When i click on one button the data will be displayed like this in the listview: colA colB colC ----- ----- ------...
5
by: Phill W. | last post by:
(VB'2003) What's the correct way to remove multiple, selected items from a ListView control (say, from a ContextMenu)? I ask because I'm getting a very annoying ArgumentOutOfRangeException...
3
by: Martin Panggabean | last post by:
Hello All, I've kind a logic problem ... I want to fill the listView control in VB.NET with data in my mySql table using Datareader object component. But It seems that the way of how listView...
1
by: plmanikandan | last post by:
Hi, I have a listview with items,subitems.I tems and subitems are added as below listView1.View = View.Details; listView1.Columns.Add("Column 1", 100,HorizontalAlignment.Center);...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.