Solved

Read ListView Items by Column Name

Posted on 2011-09-06
5
377 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now