Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Foreach Sub Item In ListView

I was wanting to be able to iterate through each of my ListViews sub items and get the value from each. I have tried various things but am finding it really difficult to just get the sub item text from the second column, not the items text from the first column. Thanks.

foreach (ListViewItem itemRow in listView1.Items)
{             
    for (int i = 0; i < itemRow.SubItems.Count; i++) 
    {
        string dueDate = itemRow.SubItems[i].Text;
        MessageBox.Show(dueDate);
    }
}
like image 723
Bali C Avatar asked Feb 23 '23 23:02

Bali C


1 Answers

After a lot of trial and error I managed to do it with this code:

for (int i = 0; i < listView1.Items.Count; i++)
{
    int ii = 1;
    MessageBox.Show(listView1.Items[i].SubItems[ii].Text);
    ii++;
}
like image 174
Bali C Avatar answered Mar 08 '23 21:03

Bali C