Solved

Loop Through ListView Items/Columns

Posted on 2009-05-05
7
1,025 Views
Last Modified: 2012-06-27
I am very new to .Net, and don't know how to loop through a listview and get it's values so that I can save in a database.
I fill the listview dynamically using...

With lst
                str(0) = CStr(iWatch1)
                str(1) = sTime
                itm = New ListViewItem(str)
                lst.Items.Add(itm)
            End With

Now I need to get the str(0) value and str(1) value to save

For i = 0 to lst.items.count - 1
How do I get the values for each column???
next

Thanks

0
Comment
Question by:Sheritlw
  • 4
  • 2
7 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24311508
0
 

Author Comment

by:Sheritlw
ID: 24311555
Unfortuntly when I click or transfer links my IE crashes.
I know I have a lot to learn about .Net.  I spent the last 15 + years programming with VB and before that with Cobol.
This app is for my sister and she needs it right away.  I figured I would develop it enough so she could use it and then rework it as I learn net.
I really just wanted an example of looping through a listview.
Thanks
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24311571
Try this...


For i = 0 to lst.items.count - 1
msgbox(lst.item(i).Subitems(0).value)
msgbox(lst.item(i).Subitems(1).value)
next

Open in new window

0
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
LVL 15

Assisted Solution

by:JackOfPH
JackOfPH earned 100 total points
ID: 24311583
oopss... change try this one
For i = 0 to lst.items.count - 1
msgbox(lst.item(i).Subitems(0).text)
msgbox(lst.item(i).Subitems(1).text)
next

Open in new window

0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 400 total points
ID: 24311589
Use something like the below example.

Wayne
For Each lvi As ListViewItem In ListView1.Items
    For c As Integer = 0 To lvi.SubItems.Count - 1
        MsgBox(lvi.SubItems(c).Text)
    Next
Next

Open in new window

0
 

Author Comment

by:Sheritlw
ID: 24311606
Unfortunely item is not an option for the list.  Items is...
I filled it using a listviewitem
With lst

                str(0) = CStr(iWatch1)
                str(1) = sTime
                itm = New ListViewItem(str)
                lst.Items.Add(itm)

            End With

Trying to figure out how to get the information out.

Thanks
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24311625

For i = 0 to lst.items.count - 1
msgbox(lst.items(i).Subitems(0).text)
msgbox(lst.items(i).Subitems(1).text)
next
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question