iterate listview

Posted on 2006-04-17
Last Modified: 2006-11-18
Hi Expert,

I want to update the listview field value but I don't want to hard code the ListView1.SubItem[2] position.

Instead of hard coding the SubItem[?] position, is there anyway I can use the listview columnheader?

Question by:4eyesgirl
    1 Comment
    LVL 96

    Accepted Solution

    public ListViewItem.ListViewSubItem GetListViewSubItem(ListView view, int index, string columnName)
     ListViewItem item = view.Items[index];
     for (int columnIndex = 0; columnIndex < view.Columns.Count; columnIndex++)
       ColumnHeader column = view.Columns[columnIndex];
       if (column.Text.ToLower() == columnName.ToLower())
         return item.SubItems[columnIndex];
     return null;


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    731 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

    16 Experts available now in Live!

    Get 1:1 Help Now