c# listviewbox

blue-coder
blue-coder used Ask the Experts™
on
I have a listview box with 2 columns (address, name).  how can I access data stored in the second column? for example I use the following code to loop through the checked items in the list view box and I have a variable to store the text in the address column, but I cannot seem to get the name column text.

            foreach (ListViewItem lv in lvDevices.CheckedItems)
            {
                string address = lv.ToString()
            }
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Engineer
Top Expert 2009
Commented:
Assuming that you add column support, on your loop change:
string address =  lv.SubItems[0].Text;
string name =  lv.SubItems[1].Text;

Check:
http://stackoverflow.com/questions/1255635/how-do-i-add-to-a-specific-column-in-listview-item

Author

Commented:
perfect. I had tried using lv.items[1] before, but it did not work.  I guess it's true that you learn 1.66 new things every 40 hours :) thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial