Solved

Read ListView Items by Column Name

Posted on 2011-09-06
5
392 Views
Last Modified: 2012-05-12
Hi, We use listView in our vb.net project (VB 2005). up until now we've been Referencing the item and sub item by index.  We'd like to change that and Reference item by it's column name.
for example:
it we have four columns in our list. i
Column1, Column2,Column3,Column4

current Code
        For i As Integer = 0 To listView1.Items.Count - 1
            Console.WriteLine(listView1.Items(i).SubItems(1).Text)
        Next

We'd like to use listView1.Items(i).SubItems("Column1").Text

I can't figure out how to do this currently, because it's not working right now.
0
Comment
Question by:vb7guy
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36490150
0
 

Author Comment

by:vb7guy
ID: 36490315
Thanks for the response. but this post doesn't work with VB.net
0
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
ID: 36490343
What is the issue with VB.net? My guess is it is a syntax change that needs to be made:

listView1.Columns("NameKey").Index
0
 

Author Comment

by:vb7guy
ID: 36490398
Here, I figured it out on my own. too bad, this isn't well documented in books online.

Console.WriteLine(listView1.Items(i).SubItems(listView1.Columns.IndexOfKey("column1")).Text)
0
 

Author Closing Comment

by:vb7guy
ID: 36490402
Since your response was kind of partial. I'll accept it as the solution.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…

685 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