[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

iterate listview

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?

Thanks.
0
4eyesgirl
Asked:
4eyesgirl
1 Solution
 
Bob LearnedCommented:
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;
}

Bob
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now