?
Solved

Read ListView Items by Column Name

Posted on 2011-09-06
5
Medium Priority
?
438 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

862 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