Link to home
Start Free TrialLog in
Avatar of vb7guy
vb7guyFlag for United States of America

asked on

Read ListView Items by Column Name

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.
Avatar of strickdd
strickdd
Flag of United States of America image

Avatar of vb7guy

ASKER

Thanks for the response. but this post doesn't work with VB.net
ASKER CERTIFIED SOLUTION
Avatar of strickdd
strickdd
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vb7guy

ASKER

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)
Avatar of vb7guy

ASKER

Since your response was kind of partial. I'll accept it as the solution.